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, #running, #scheduler, #t

Instance Method Summary collapse

Methods inherited from Job

#schedule_info, #tags, #tags=, #trigger, #trigger_block, #unschedule

Constructor Details

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

Creates a new CronJob instance.



329
330
331
332
333
334
335
336
337
338
339
340
# File 'lib/rufus/sc/jobs.rb', line 329

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

  super

  @cron_line = case @t

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

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

Instance Attribute Details

#blockObject (readonly)

The block to call when triggering



325
326
327
# File 'lib/rufus/sc/jobs.rb', line 325

def block
  @block
end

#cron_lineObject (readonly)

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



317
318
319
# File 'lib/rufus/sc/jobs.rb', line 317

def cron_line
  @cron_line
end

#paramsObject (readonly)

The job parameters (passed via the schedule method)



321
322
323
# File 'lib/rufus/sc/jobs.rb', line 321

def params
  @params
end

Instance Method Details

#next_time(from = Time.now) ⇒ Object

Returns the next time this job is meant to trigger



349
350
351
352
# File 'lib/rufus/sc/jobs.rb', line 349

def next_time (from=Time.now)

  @cron_line.next_time(from)
end

#trigger_if_matches(time) ⇒ Object



342
343
344
345
# File 'lib/rufus/sc/jobs.rb', line 342

def trigger_if_matches (time)

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