Class: Rufus::Scheduler::CronJob

Inherits:
Job
  • Object
show all
Defined in:
lib/rufus/sc/jobs.rb

Overview

Recurring job, cron style.

Instance Attribute Summary collapse

Attributes inherited from Job

#job_id, #last, #last_job_thread, #scheduler, #t

Instance Method Summary collapse

Methods inherited from Job

#pause, #paused?, #resume, #running, #schedule_info, #tags, #tags=, #trigger, #trigger_block, #unschedule

Constructor Details

#initialize(scheduler, cron_string, params, &block) ⇒ CronJob

Creates a new CronJob instance.



430
431
432
433
434
435
436
437
438
439
440
441
442
# File 'lib/rufus/sc/jobs.rb', line 430

def initialize(scheduler, cron_string, params, &block)

  super

  @cron_line = case @t

    when String then CronLine.new(@t)
    when CronLine then @t

    else raise ArgumentError.new(
      "cannot initialize a CronJob out of #{@t.inspect}")
  end
end

Instance Attribute Details

#blockObject (readonly)

The block to call when triggering



426
427
428
# File 'lib/rufus/sc/jobs.rb', line 426

def block
  @block
end

#cron_lineObject (readonly)

The CronLine instance, it holds all the info about the cron schedule



418
419
420
# File 'lib/rufus/sc/jobs.rb', line 418

def cron_line
  @cron_line
end

#paramsObject (readonly)

The job parameters (passed via the schedule method)



422
423
424
# File 'lib/rufus/sc/jobs.rb', line 422

def params
  @params
end

Instance Method Details

#next_time(from = Time.now) ⇒ Object

Returns the next time this job is meant to trigger



453
454
455
456
# File 'lib/rufus/sc/jobs.rb', line 453

def next_time(from=Time.now)

  @cron_line.next_time(from)
end

#trigger_if_matches(time) ⇒ Object



444
445
446
447
448
449
# File 'lib/rufus/sc/jobs.rb', line 444

def trigger_if_matches(time)

  return if @paused

  trigger(time) if @cron_line.matches?(time)
end