diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2014-05-22 19:33:23 +0200 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2014-05-22 19:33:23 +0200 |
commit | c073ba339a6820625718f7320989cfa527534563 (patch) | |
tree | bcc70b5fcb6103f285659762b0670beabb598e19 /lib/active_job/callbacks.rb | |
parent | f82bc7e5515d439b5125d7596b56563249b2d83e (diff) | |
download | rails-c073ba339a6820625718f7320989cfa527534563.tar.gz rails-c073ba339a6820625718f7320989cfa527534563.tar.bz2 rails-c073ba339a6820625718f7320989cfa527534563.zip |
Add callbacks, implement instrumentation as callbacks, and have the enqueue methods return a job instance
Diffstat (limited to 'lib/active_job/callbacks.rb')
-rw-r--r-- | lib/active_job/callbacks.rb | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/active_job/callbacks.rb b/lib/active_job/callbacks.rb new file mode 100644 index 0000000000..c69e4a3b55 --- /dev/null +++ b/lib/active_job/callbacks.rb @@ -0,0 +1,40 @@ +require 'active_support/callbacks' + +module ActiveJob + module Callbacks + extend ActiveSupport::Concern + include ActiveSupport::Callbacks + + included do + define_callbacks :perform + define_callbacks :enqueue + end + + module ClassMethods + def before_perform(*filters, &blk) + set_callback(:perform, :before, *filters, &blk) + end + + def after_perform(*filters, &blk) + set_callback(:perform, :after, *filters, &blk) + end + + def around_perform(*filters, &blk) + set_callback(:perform, :around, *filters, &blk) + end + + + def before_enqueue(*filters, &blk) + set_callback(:enqueue, :before, *filters, &blk) + end + + def after_enqueue(*filters, &blk) + set_callback(:enqueue, :after, *filters, &blk) + end + + def around_enqueue(*filters, &blk) + set_callback(:enqueue, :around, *filters, &blk) + end + end + end +end
\ No newline at end of file |