diff options
Diffstat (limited to 'activejob/test/jobs')
-rw-r--r-- | activejob/test/jobs/callback_job.rb | 29 | ||||
-rw-r--r-- | activejob/test/jobs/gid_job.rb | 8 | ||||
-rw-r--r-- | activejob/test/jobs/hello_job.rb | 7 | ||||
-rw-r--r-- | activejob/test/jobs/kwargs_job.rb | 7 | ||||
-rw-r--r-- | activejob/test/jobs/logging_job.rb | 10 | ||||
-rw-r--r-- | activejob/test/jobs/nested_job.rb | 10 | ||||
-rw-r--r-- | activejob/test/jobs/rescue_job.rb | 27 |
7 files changed, 98 insertions, 0 deletions
diff --git a/activejob/test/jobs/callback_job.rb b/activejob/test/jobs/callback_job.rb new file mode 100644 index 0000000000..891ed9464e --- /dev/null +++ b/activejob/test/jobs/callback_job.rb @@ -0,0 +1,29 @@ +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 do |job, block| + job.history << "CallbackJob ran around_perform_start" + block.call + job.history << "CallbackJob ran around_perform_stop" + end + + around_enqueue do |job, block| + job.history << "CallbackJob ran around_enqueue_start" + block.call + job.history << "CallbackJob ran around_enqueue_stop" + end + + + def perform(person = "david") + # NOTHING! + end + + def history + @history ||= [] + end + +end diff --git a/activejob/test/jobs/gid_job.rb b/activejob/test/jobs/gid_job.rb new file mode 100644 index 0000000000..e485bfa2dd --- /dev/null +++ b/activejob/test/jobs/gid_job.rb @@ -0,0 +1,8 @@ +require_relative '../support/job_buffer' + +class GidJob < ActiveJob::Base + def perform(person) + JobBuffer.add("Person with ID: #{person.id}") + end +end + diff --git a/activejob/test/jobs/hello_job.rb b/activejob/test/jobs/hello_job.rb new file mode 100644 index 0000000000..022fa58e4a --- /dev/null +++ b/activejob/test/jobs/hello_job.rb @@ -0,0 +1,7 @@ +require_relative '../support/job_buffer' + +class HelloJob < ActiveJob::Base + def perform(greeter = "David") + JobBuffer.add("#{greeter} says hello") + end +end diff --git a/activejob/test/jobs/kwargs_job.rb b/activejob/test/jobs/kwargs_job.rb new file mode 100644 index 0000000000..2df17d15ae --- /dev/null +++ b/activejob/test/jobs/kwargs_job.rb @@ -0,0 +1,7 @@ +require_relative '../support/job_buffer' + +class KwargsJob < ActiveJob::Base + def perform(argument: 1) + JobBuffer.add("Job with argument: #{argument}") + end +end diff --git a/activejob/test/jobs/logging_job.rb b/activejob/test/jobs/logging_job.rb new file mode 100644 index 0000000000..d84ed8589b --- /dev/null +++ b/activejob/test/jobs/logging_job.rb @@ -0,0 +1,10 @@ +class LoggingJob < ActiveJob::Base + def perform(dummy) + logger.info "Dummy, here is it: #{dummy}" + end + + def job_id + "LOGGING-JOB-ID" + end +end + diff --git a/activejob/test/jobs/nested_job.rb b/activejob/test/jobs/nested_job.rb new file mode 100644 index 0000000000..8c4ec549a6 --- /dev/null +++ b/activejob/test/jobs/nested_job.rb @@ -0,0 +1,10 @@ +class NestedJob < ActiveJob::Base + def perform + LoggingJob.perform_later "NestedJob" + end + + def job_id + "NESTED-JOB-ID" + end +end + diff --git a/activejob/test/jobs/rescue_job.rb b/activejob/test/jobs/rescue_job.rb new file mode 100644 index 0000000000..f1b9c9349e --- /dev/null +++ b/activejob/test/jobs/rescue_job.rb @@ -0,0 +1,27 @@ +require_relative '../support/job_buffer' + +class RescueJob < ActiveJob::Base + class OtherError < StandardError; end + + rescue_from(ArgumentError) do + JobBuffer.add('rescued from ArgumentError') + arguments[0] = "DIFFERENT!" + retry_job + end + + rescue_from(ActiveJob::DeserializationError) do |e| + JobBuffer.add('rescued from DeserializationError') + JobBuffer.add("DeserializationError original exception was #{e.original_exception.class.name}") + end + + def perform(person = "david") + case person + when "david" + raise ArgumentError, "Hair too good" + when "other" + raise OtherError + else + JobBuffer.add('performed beautifully') + end + end +end |