lib/rocket_job/plugins/job/state_machine.rb in rocketjob-3.3.0 vs lib/rocket_job/plugins/job/state_machine.rb in rocketjob-3.3.1
- old
+ new
@@ -56,16 +56,18 @@
event :retry do
transitions from: :failed, to: :queued
end
event :pause do
- transitions from: :running, to: :paused
+ transitions from: :running, to: :paused, if: :pausable?
+ # All jobs are pausable prior to starting the job.
transitions from: :queued, to: :paused
end
event :resume do
- transitions from: :paused, to: :running, if: -> { started_at }
+ transitions from: :paused, to: :running, if: -> { pausable? && started_at }
+ # All jobs paused before processing started are pausable.
transitions from: :paused, to: :queued, unless: -> { started_at }
end
event :abort do
transitions from: :running, to: :aborted
@@ -79,9 +81,13 @@
if: -> server_name { worker_on_server?(server_name) },
after: :rocket_job_clear_started_at
end
end
# @formatter:on
+
+ # By default all jobs are not pausable / resumable
+ class_attribute(:pausable)
+ self.pausable = false
# Define a before and after callback method for each event
state_machine_define_event_callbacks(*aasm.state_machine.events.keys)
before_start :rocket_job_set_started_at