Class: Scheddy::TaskDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/scheddy/config.rb

Instance Method Summary collapse

Instance Method Details

#initial_delay(duration) ⇒ Object

duration - Duration or Integer (nil = random delay)



97
98
99
# File 'lib/scheddy/config.rb', line 97

def initial_delay(duration)
  task[:initial_delay] = duration&.to_i
end

#logger_tag(tag) ⇒ Object

tag - String or false/nil; defaults to :name



102
103
104
# File 'lib/scheddy/config.rb', line 102

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’

Raises:

  • (ArgumentError)


65
66
67
68
69
# File 'lib/scheddy/config.rb', line 65

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 * * *”



72
73
74
75
76
77
# File 'lib/scheddy/config.rb', line 72

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



80
81
82
# File 'lib/scheddy/config.rb', line 80

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



90
91
92
93
94
# File 'lib/scheddy/config.rb', line 90

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_taskObject

private api



112
113
114
# File 'lib/scheddy/config.rb', line 112

def to_task
  Task.new(**as_args)
end

#track_runs(bool) ⇒ Object



106
107
108
# File 'lib/scheddy/config.rb', line 106

def track_runs(bool)
  task[:track_runs] = bool
end