Skip to content

Commit

Permalink
add before_event
Browse files Browse the repository at this point in the history
  • Loading branch information
kostya committed May 29, 2015
1 parent 0be581e commit 258eb0c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
5 changes: 5 additions & 0 deletions lib/pgq/consumer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ def self.add_event(method_name, *args)

# == magick consume

def before_event(method_name, *args)
# just callback, redefine if needed
end

def perform(method_name, *args)
self.before_event(method_name, *args)
self.send(method_name, *args)
end

Expand Down
6 changes: 1 addition & 5 deletions lib/pgq/consumer_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,7 @@ def perform_event(event)

perform(type, *data)

rescue Exception => ex
error(event.exception_message(ex))
event.failed!(ex)

rescue => ex
rescue Object => ex
error(event.exception_message(ex))
event.failed!(ex)
end
Expand Down
7 changes: 6 additions & 1 deletion spec/consumer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,10 @@
$a.should == 111
$b.should == 'abc'
end


it "before_event" do
PgqCallback.proxy(:bla)
PgqCallback.bla(111)
$x.should == 123
end
end
10 changes: 10 additions & 0 deletions spec/support/spec_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ def ptest2(a, b)

end

class PgqCallback < Pgq::Consumer
def before_event(method_name, *args)
@x = 12
end

def bla(x)
$x = x + @x
end
end

def start_ticker
conf = "#{ENV['RAILS_ROOT']}/config/pgq_#{ENV['RAILS_ENV']}.ini"
output = `which pgqadm.py && pgqadm.py #{conf} -d ticker 2>&1 || which pgqadm && pgqadm #{conf} -d ticker 2>&1`
Expand Down

0 comments on commit 258eb0c

Please sign in to comment.