lib/rocket_job/plugins/restart.rb in rocketjob-2.1.2 vs lib/rocket_job/plugins/restart.rb in rocketjob-2.1.3
- old
+ new
@@ -15,14 +15,15 @@
# - A validation fails after cloning this job.
# - The job has expired.
module Restart
extend ActiveSupport::Concern
- # Attributes to exclude when copying across the attributes to the new instance
- RESTART_EXCLUDES = %w(_id state created_at started_at completed_at failure_count worker_name percent_complete exception result run_at record_count sub_state)
-
included do
+ # Attributes to exclude when copying across the attributes to the new instance
+ class_attribute :rocket_job_restart_excludes
+ self.rocket_job_restart_excludes = %w(_id state created_at started_at completed_at failure_count worker_name percent_complete exception result run_at record_count sub_state)
+
after_abort :rocket_job_restart_new_instance
after_complete :rocket_job_restart_new_instance
after_fail :rocket_job_restart_abort
end
@@ -30,10 +31,10 @@
# Run again in the future, even if this run fails with an exception
def rocket_job_restart_new_instance
return if expired?
attrs = attributes.dup
- RESTART_EXCLUDES.each { |attr| attrs.delete(attr) }
+ rocket_job_restart_excludes.each { |attr| attrs.delete(attr) }
# Copy across run_at for future dated jobs
attrs['run_at'] = run_at if run_at && (run_at > Time.now)
# Allow Singleton to prevent the creation of a new job if one is already running
job = self.class.create(attrs)