class Scron::Schedule

Overview

Wraps a single line in the schedule file. Made up of two parts, the interval and the command. Determines if a command is overdue and needs to be run. Does this by translating interval string into number of days since last run until command is considered overdue.

Defined in:

scron/schedule.cr

Constant Summary

WEEKDAYS = {"Mo" => 1, "Tu" => 2, "We" => 3, "Th" => 4, "Fr" => 5, "Sa" => 6, "Su" => 7}

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(line : String, now : Time) #

Returns a schedule with an interval and command. Example usage:

Scron::Schedule.new("Mo,We echo", Time.local) # run every Monday/Wednesday
Scron::Schedule.new("23rd echo", Time.local)  # run on the 23rd of every month
Scron::Schedule.new("12/25 echo", Time.local) # run on December 25th every year
Scron::Schedule.new("10d echo", Time.local)   # run once every 10 days

[View source]

Class Method Detail

def self.parse(text : String, now : Time) : Array(Scron::Schedule) #

Given the text of a schedule file, parses it and returns an Array of Schedules. Lines prefixed with # are ignored as a comment. Empty lines are also ignored.


[View source]

Instance Method Detail

def command : String #

[View source]
def interval : Int32 #

[View source]
def overdue?(history : History) #

Returns true if command should run now, if it satisfies any of these conditions:

  • command has never ran
  • interval is past due, example: it last ran 15 days ago but the interval is every 14 days

[View source]