From 8b5c04e423cbfd90a15ed6fbab3f111803bc6544 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 29 Jul 2016 13:54:55 -0700 Subject: Add retry_on/discard_on for better exception handling --- activejob/test/jobs/retry_job.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 activejob/test/jobs/retry_job.rb (limited to 'activejob/test/jobs/retry_job.rb') diff --git a/activejob/test/jobs/retry_job.rb b/activejob/test/jobs/retry_job.rb new file mode 100644 index 0000000000..2e05f95bf6 --- /dev/null +++ b/activejob/test/jobs/retry_job.rb @@ -0,0 +1,21 @@ +require_relative '../support/job_buffer' +require 'active_support/core_ext/integer/inflections' + +class SeriousError < StandardError; end +class VerySeriousError < StandardError; end +class NotSeriousError < StandardError; end + +class RetryJob < ActiveJob::Base + retry_on SeriousError + retry_on VerySeriousError, wait: 1.second, attempts: 10 + discard_on NotSeriousError + + def perform(raising, attempts) + if executions < attempts + JobBuffer.add("Raised #{raising} for the #{executions.ordinalize} time") + raise raising.constantize + else + JobBuffer.add("Successfully completed job") + end + end +end -- cgit v1.2.3