Module: Taskmaster::Henchman::ClassMethods

Defined in:
lib/taskmaster/henchman.rb

Instance Method Summary collapse

Instance Method Details

#cron_outputString

Cron syntax generated from the jobs scheduled in the including class

Returns:

  • (String)

    the cron syntax string



41
42
43
# File 'lib/taskmaster/henchman.rb', line 41

def cron_output
  Whenever::JobList.new(@scheduled_jobs.join("\n")).generate_cron_output
end

#every(frequency, options = {}) ⇒ Object

Declares the cron job using whenever syntax.

Parameters:

  • frequency (Integer, #to_s)

    any frequency defined as valid for whenever (e.g., 600 (seconds), 1.day, :sunday, '0 12 * * *')

  • options (Hash) (defaults to: {})

    configuration options

Options Hash (options):

  • :run (Symbol) — default: :run

    the class method to call in the cron job

  • :with (Symbol) — default: :runner

    the whenever job type to use when defining the cron job

  • :at (Integer, #to_s)

    a specific time to start the cron job (e.g., every :hour, :at => 6' runs a job 6 minutes after every hour;every :day, :at => '4:30 am' runs a job at 4:30 am every day.)



24
25
26
27
28
29
30
31
# File 'lib/taskmaster/henchman.rb', line 24

def every(frequency, options = {})
  @scheduled_jobs ||= []
  method  = options.delete(:run) || :run
  command = options.delete(:with) || :runner
  @scheduled_jobs << "every #{frequency.to_s}, #{options.inspect} do
  #{command.to_s} \'#{self.name}.#{method.to_s}\'
end"
end

#runObject

Must be overridden by including classes



34
35
36
# File 'lib/taskmaster/henchman.rb', line 34

def run
  raise 'Not implemented'
end

#scheduled_jobsArray

Jobs scheduled by the including class

Returns:

  • (Array)

    an array of whenever-syntax jobs



48
49
50
# File 'lib/taskmaster/henchman.rb', line 48

def scheduled_jobs
  @scheduled_jobs
end