aboutsummaryrefslogtreecommitdiffstats
path: root/test/jobs/callback_job.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 /test/jobs/callback_job.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 'test/jobs/callback_job.rb')
-rw-r--r--test/jobs/callback_job.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/jobs/callback_job.rb b/test/jobs/callback_job.rb
new file mode 100644
index 0000000000..056dd073e8
--- /dev/null
+++ b/test/jobs/callback_job.rb
@@ -0,0 +1,32 @@
+class CallbackJob < ActiveJob::Base
+ before_perform ->(job) { job.history << "CallbackJob ran before_perform" }
+ after_perform ->(job) { job.history << "CallbackJob ran after_perform" }
+
+ before_enqueue ->(job) { job.history << "CallbackJob ran before_enqueue" }
+ after_enqueue ->(job) { job.history << "CallbackJob ran after_enqueue" }
+
+ around_perform :around_perform
+ around_enqueue :around_enqueue
+
+
+ def perform(person = "david")
+ # NOTHING!
+ end
+
+ def history
+ @history ||= []
+ end
+
+ # FIXME: Not sure why these can't be declared inline like before/after
+ def around_perform
+ history << "CallbackJob ran around_perform_start"
+ yield
+ history << "CallbackJob ran around_perform_stop"
+ end
+
+ def around_enqueue
+ history << "CallbackJob ran around_enqueue_start"
+ yield
+ history << "CallbackJob ran around_enqueue_stop"
+ end
+end