allow comma in raw cron syntax
This commit is contained in:
parent
78786a4465
commit
cc6bafb37a
@ -1,6 +1,7 @@
|
|||||||
module Whenever
|
module Whenever
|
||||||
module Output
|
module Output
|
||||||
class Cron
|
class Cron
|
||||||
|
REGEX = /^.+ .+ .+ .+ .+.?$/
|
||||||
|
|
||||||
attr_accessor :time, :task
|
attr_accessor :time, :task
|
||||||
|
|
||||||
@ -10,9 +11,14 @@ module Whenever
|
|||||||
@at = at.is_a?(String) ? (Chronic.parse(at) || 0) : (at || 0)
|
@at = at.is_a?(String) ? (Chronic.parse(at) || 0) : (at || 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.enumerate(item)
|
def self.enumerate(item, detect_cron = true)
|
||||||
if item and item.is_a?(String)
|
if item and item.is_a?(String)
|
||||||
items = item.split(',')
|
items =
|
||||||
|
if detect_cron && item =~ REGEX
|
||||||
|
[item]
|
||||||
|
else
|
||||||
|
item.split(',')
|
||||||
|
end
|
||||||
else
|
else
|
||||||
items = item
|
items = item
|
||||||
items = [items] unless items and items.respond_to?(:each)
|
items = [items] unless items and items.respond_to?(:each)
|
||||||
@ -22,7 +28,7 @@ module Whenever
|
|||||||
|
|
||||||
def self.output(times, job)
|
def self.output(times, job)
|
||||||
enumerate(times).each do |time|
|
enumerate(times).each do |time|
|
||||||
enumerate(job.at).each do |at|
|
enumerate(job.at, false).each do |at|
|
||||||
yield new(time, job.output, at).output
|
yield new(time, job.output, at).output
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -34,7 +40,7 @@ module Whenever
|
|||||||
|
|
||||||
def time_in_cron_syntax
|
def time_in_cron_syntax
|
||||||
case @time
|
case @time
|
||||||
when /^.+ .+ .+ .+ .+.?$/ then @time # raw cron sytax given
|
when REGEX then @time # raw cron sytax given
|
||||||
when Symbol then parse_symbol
|
when Symbol then parse_symbol
|
||||||
when String then parse_as_string
|
when String then parse_as_string
|
||||||
else parse_time
|
else parse_time
|
||||||
|
@ -254,14 +254,14 @@ class OutputAtTest < Test::Unit::TestCase
|
|||||||
@output = Whenever.cron \
|
@output = Whenever.cron \
|
||||||
<<-file
|
<<-file
|
||||||
set :job_template, nil
|
set :job_template, nil
|
||||||
every '0 0 27-31 * *' do
|
every '0 0 27,31 * *' do
|
||||||
command "blahblah"
|
command "blahblah"
|
||||||
end
|
end
|
||||||
file
|
file
|
||||||
end
|
end
|
||||||
|
|
||||||
should "output the command using the same cron syntax" do
|
should "output the command using the same cron syntax" do
|
||||||
assert_match '0 0 27-31 * * blahblah', @output
|
assert_match '0 0 27,31 * * blahblah', @output
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user