lib/rufus/sc/jobs.rb in rufus-scheduler-2.0.13 vs lib/rufus/sc/jobs.rb in rufus-scheduler-2.0.14
- old
+ new
@@ -75,10 +75,11 @@
@t = t
@params = params
@block = block || params[:schedulable]
@running = false
+ @paused = false
raise ArgumentError.new(
'no block or :schedulable passed, nothing to schedule'
) unless @block
@@ -89,17 +90,52 @@
determine_at
end
# Returns true if this job is currently running (in the middle of #trigger)
#
+ # Note : paused? is not related to running?
+ #
def running
@running
end
alias running? running
+ # Returns true if this job is paused, false else.
+ #
+ # A paused job is still scheduled, but does not trigger.
+ #
+ # Note : paused? is not related to running?
+ #
+ def paused?
+
+ @paused
+ end
+
+ # Pauses this job (sets the paused flag to true).
+ #
+ # Note that it will not pause the execution of a block currently 'running'.
+ # Future triggering of the job will not occur until #resume is called.
+ #
+ # Note too that, during the pause time, the schedule kept the same. Calling
+ # #resume will not force old triggers in.
+ #
+ def pause
+
+ @paused = true
+ end
+
+ # Resumes this job (sets the paused flag to false).
+ #
+ # This job will trigger again.
+ #
+ def resume
+
+ @paused = false
+ end
+
# Returns the list of tags attached to the job.
#
def tags
@params[:tags]
@@ -123,10 +159,12 @@
# Triggers the job.
#
def trigger(t=Time.now)
+ return if @paused
+
@last = t
job_thread = nil
to_job = nil
return if @running and (params[:allow_overlapping] == false)
@@ -350,9 +388,11 @@
"cannot initialize a CronJob out of #{@t.inspect}")
end
end
def trigger_if_matches(time)
+
+ return if @paused
trigger(time) if @cron_line.matches?(time)
end
# Returns the next time this job is meant to trigger