aboutsummaryrefslogtreecommitdiffstats
path: root/activejob/test/jobs
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2016-07-29 13:54:55 -0700
committerDavid Heinemeier Hansson <david@loudthinking.com>2016-07-29 13:54:55 -0700
commit8b5c04e423cbfd90a15ed6fbab3f111803bc6544 (patch)
treee96cb1cbcf2a7732c97a01a345dc384321505f92 /activejob/test/jobs
parent3916656f8e9700eb5f1cfc441ff66e1f12173683 (diff)
downloadrails-8b5c04e423cbfd90a15ed6fbab3f111803bc6544.tar.gz
rails-8b5c04e423cbfd90a15ed6fbab3f111803bc6544.tar.bz2
rails-8b5c04e423cbfd90a15ed6fbab3f111803bc6544.zip
Add retry_on/discard_on for better exception handling
Diffstat (limited to 'activejob/test/jobs')
-rw-r--r--activejob/test/jobs/retry_job.rb21
1 files changed, 21 insertions, 0 deletions
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