Class: Rufus::Scheduler::RepeatJob
- Defined in:
- lib/rufus/scheduler/jobs.rb
Instance Attribute Summary collapse
-
#first_at ⇒ Object
Returns the value of attribute first_at.
-
#last_at ⇒ Object
Returns the value of attribute last_at.
-
#paused_at ⇒ Object
readonly
Returns the value of attribute paused_at.
-
#times ⇒ Object
Returns the value of attribute times.
Attributes inherited from Job
#callable, #count, #handler, #id, #last_time, #last_work_time, #mean_work_time, #next_time, #opts, #original, #scheduled_at, #tags, #unscheduled_at
Instance Method Summary collapse
- #determine_id ⇒ Object
-
#initialize(scheduler, duration, opts, block) ⇒ RepeatJob
constructor
A new instance of RepeatJob.
- #occurrences(time0, time1) ⇒ Object
- #pause ⇒ Object
- #paused? ⇒ Boolean
- #resume ⇒ Object
- #trigger(time) ⇒ Object
Methods inherited from Job
#[], #[]=, #call, #key?, #keys, #kill, #running?, #scheduled?, #threads, #unschedule
Constructor Details
#initialize(scheduler, duration, opts, block) ⇒ RepeatJob
Returns a new instance of RepeatJob.
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 |
# File 'lib/rufus/scheduler/jobs.rb', line 397 def initialize(scheduler, duration, opts, block) super @paused_at = nil @times = opts[:times] raise ArgumentError.new( "cannot accept :times => #{@times.inspect}, not nil or an int" ) unless @times == nil || @times.is_a?(Fixnum) self.first_at = opts[:first] || opts[:first_time] || opts[:first_at] || opts[:first_in] || nil self.last_at = opts[:last] || opts[:last_at] || opts[:last_in] end |
Instance Attribute Details
#first_at ⇒ Object
Returns the value of attribute first_at.
393 394 395 |
# File 'lib/rufus/scheduler/jobs.rb', line 393 def first_at @first_at end |
#last_at ⇒ Object
Returns the value of attribute last_at.
394 395 396 |
# File 'lib/rufus/scheduler/jobs.rb', line 394 def last_at @last_at end |
#paused_at ⇒ Object (readonly)
Returns the value of attribute paused_at.
391 392 393 |
# File 'lib/rufus/scheduler/jobs.rb', line 391 def paused_at @paused_at end |
#times ⇒ Object
Returns the value of attribute times.
395 396 397 |
# File 'lib/rufus/scheduler/jobs.rb', line 395 def times @times end |
Instance Method Details
#determine_id ⇒ Object
471 472 473 474 475 476 477 478 |
# File 'lib/rufus/scheduler/jobs.rb', line 471 def determine_id [ self.class.name.split(':').last.downcase[0..-4], @scheduled_at.to_f, self.hash.abs ].map(&:to_s).join('_') end |
#occurrences(time0, time1) ⇒ Object
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 |
# File 'lib/rufus/scheduler/jobs.rb', line 480 def occurrences(time0, time1) a = [] nt = @next_time ts = @times loop do break if nt > time1 break if ts && ts <= 0 a << nt if nt >= time0 nt = next_time_from(nt) ts = ts - 1 if ts end a end |
#pause ⇒ Object
456 457 458 459 |
# File 'lib/rufus/scheduler/jobs.rb', line 456 def pause @paused_at = Time.now end |
#paused? ⇒ Boolean
466 467 468 469 |
# File 'lib/rufus/scheduler/jobs.rb', line 466 def paused? @paused_at != nil end |
#resume ⇒ Object
461 462 463 464 |
# File 'lib/rufus/scheduler/jobs.rb', line 461 def resume @paused_at = nil end |
#trigger(time) ⇒ Object
442 443 444 445 446 447 448 449 450 451 452 453 454 |
# File 'lib/rufus/scheduler/jobs.rb', line 442 def trigger(time) return if @paused_at return (@next_time = nil) if @times && @times < 1 return (@next_time = nil) if @last_at && time >= @last_at # # TODO: rework that, jobs are thus kept 1 step too much in @jobs super @times -= 1 if @times end |