Class: Scheddy::TaskDefinition
- Inherits:
-
Object
- Object
- Scheddy::TaskDefinition
- Defined in:
- lib/scheddy/config.rb
Instance Method Summary collapse
-
#initial_delay(duration) ⇒ Object
duration - Duration or Integer (nil = random delay).
-
#logger_tag(tag) ⇒ Object
tag - String or false/nil; defaults to :name.
-
#perform(string = nil, &block) ⇒ Object
block - task to perform string - task to perform as evalable code, eg: ‘SomeJob.perform_later’.
-
#run_at(cron) ⇒ Object
cron - String(“min hour dom mon dow”), eg “0 4 * * *”.
-
#run_every(duration) ⇒ Object
duration - Duration or Integer.
-
#run_when(day: '*', month: '*', date: '*', hour: '*', minute: '*', second: '0') ⇒ Object
day - day of week as Symbol (:monday, :mon) or Integer (both 0 and 7 are sunday) month - month as Symbol (:january, :jan) or Integer 1-12 date - day of month, 1-31 hour - 0-23 minute - 0-59 second - 0-59.
-
#to_task ⇒ Object
private api.
- #track_runs(bool) ⇒ Object
Instance Method Details
#initial_delay(duration) ⇒ Object
duration - Duration or Integer (nil = random delay)
90 91 92 |
# File 'lib/scheddy/config.rb', line 90 def initial_delay(duration) task[:initial_delay] = duration&.to_i end |
#logger_tag(tag) ⇒ Object
tag - String or false/nil; defaults to :name
95 96 97 |
# File 'lib/scheddy/config.rb', line 95 def logger_tag(tag) task[:tag] = tag end |
#perform(string = nil, &block) ⇒ Object
block - task to perform string - task to perform as evalable code, eg: ‘SomeJob.perform_later’
58 59 60 61 62 |
# File 'lib/scheddy/config.rb', line 58 def perform(string=nil, &block) raise ArgumentError, 'Must provide string or block to perform' unless string.is_a?(String) ^ block block ||= lambda { eval(string) } task[:task] = block end |
#run_at(cron) ⇒ Object
cron - String(“min hour dom mon dow”), eg “0 4 * * *”
65 66 67 68 69 70 |
# File 'lib/scheddy/config.rb', line 65 def run_at(cron) task[:cron] = Fugit.parse_cronish(cron) || Fugit.parse_cronish("every #{cron}") || raise(ArgumentError, "Unable to parse '#{cron}'") end |
#run_every(duration) ⇒ Object
duration - Duration or Integer
73 74 75 |
# File 'lib/scheddy/config.rb', line 73 def run_every(duration) task[:interval] = duration.to_i end |
#run_when(day: '*', month: '*', date: '*', hour: '*', minute: '*', second: '0') ⇒ Object
day - day of week as Symbol (:monday, :mon) or Integer (both 0 and 7 are sunday) month - month as Symbol (:january, :jan) or Integer 1-12 date - day of month, 1-31 hour - 0-23 minute - 0-59 second - 0-59
83 84 85 86 87 |
# File 'lib/scheddy/config.rb', line 83 def run_when(day: '*', month: '*', date: '*', hour: '*', minute: '*', second: '0') day = day.to_s[0,3] if day.to_s =~ /[a-z]/ month = month.to_s[0,3] if month.to_s =~ /[a-z]/ run_at [second, minute, hour, date, month, day].map{normalize_val _1}.join(' ') end |
#to_task ⇒ Object
private api
105 106 107 |
# File 'lib/scheddy/config.rb', line 105 def to_task Task.new(**as_args) end |
#track_runs(bool) ⇒ Object
99 100 101 |
# File 'lib/scheddy/config.rb', line 99 def track_runs(bool) task[:track_runs] = bool end |