class ScheduleJob::Cron::Job
Attributes
line_number[R]
schedule_spec[R]
Public Class Methods
every(duration_quantity, duration_unit_of_time, command)
click to toggle source
# File lib/schedule_job/cron.rb, line 161 def self.every(duration_quantity, duration_unit_of_time, command) now = DateTime.now next_moment = now + 1.minute minute = next_moment.minute hour = next_moment.hour day = next_moment.day schedule_spec = case duration_unit_of_time when "m" "*/#{duration_quantity} * * * *" when "h" "#{minute} */#{duration_quantity} * * *" when "d" "#{minute} #{hour} */#{duration_quantity} * *" when "M" "#{minute} #{hour} #{day} */#{duration_quantity} *" end self.new(schedule_spec, command) end
every_simple_duration(duration, command)
click to toggle source
duration is one of: reboot, year, month, week, day, hour
# File lib/schedule_job/cron.rb, line 181 def self.every_simple_duration(duration, command) schedule_spec = case duration when "reboot" "@reboot" when "year" "@yearly" when "month" "@monthly" when "week" "@weekly" when "day" "@daily" when "hour" "@hourly" end self.new(schedule_spec, command) end
new(schedule_spec, command, line_number = nil, pos_offset = nil)
click to toggle source
line_numbrer is the 1-based index into the crontab file that this job was found at pos_offset is the 0-based index into the crontab file that this job was found at
# File lib/schedule_job/cron.rb, line 209 def initialize(schedule_spec, command, line_number = nil, pos_offset = nil) @schedule_spec = schedule_spec @command = command @pos_offset = pos_offset @line_number = line_number end
Public Instance Methods
escaped_command()
click to toggle source
# File lib/schedule_job/cron.rb, line 220 def escaped_command Shellwords.escape(@command).gsub("%", "\%") # % is a special character in cron job specifications; see https://serverfault.com/questions/274475/escaping-double-quotes-and-percent-signs-in-cron end
specification()
click to toggle source
# File lib/schedule_job/cron.rb, line 216 def specification "#{@schedule_spec} #{escaped_command}" end
to_s()
click to toggle source
# File lib/schedule_job/cron.rb, line 224 def to_s schedule = case @schedule_spec when "@reboot" "at every reboot" when "@yearly", "@annually" "every year" when "@monthly" "every month" when "@weekly" "every week" when "@daily" "every day" when "@hourly" "every hour" else Cronex::ExpressionDescriptor.new(@schedule_spec).description end # str = "#{@command} #{schedule} (line #{@line_number}, pos #{@pos_offset})" str = "#{@command} #{schedule}" end