aboutsummaryrefslogtreecommitdiffstats
path: root/lib/active_job/callbacks.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2014-05-22 19:33:23 +0200
committerDavid Heinemeier Hansson <david@loudthinking.com>2014-05-22 19:33:23 +0200
commitc073ba339a6820625718f7320989cfa527534563 (patch)
treebcc70b5fcb6103f285659762b0670beabb598e19 /lib/active_job/callbacks.rb
parentf82bc7e5515d439b5125d7596b56563249b2d83e (diff)
downloadrails-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.rb40
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