Allow multiple ":at" times, separated by commas
Signed-off-by: Javan Makhmali <javan@javan.us>
This commit is contained in:
parent
2bd1660386
commit
abab2f8835
@ -94,12 +94,13 @@ module Whenever
|
|||||||
output = []
|
output = []
|
||||||
@jobs.each do |time, jobs|
|
@jobs.each do |time, jobs|
|
||||||
jobs.each do |job|
|
jobs.each do |job|
|
||||||
cron = Whenever::Output::Cron.output(time, job)
|
Whenever::Output::Cron.output(time, job) do |cron|
|
||||||
cron << " >> #{job.cron_log} 2>&1" if job.cron_log
|
cron << " >> #{job.cron_log} 2>&1" if job.cron_log
|
||||||
cron << "\n\n"
|
cron << "\n\n"
|
||||||
output << cron
|
output << cron
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
output.join
|
output.join
|
||||||
end
|
end
|
||||||
|
@ -12,8 +12,16 @@ module Whenever
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.output(time, job)
|
def self.output(time, job)
|
||||||
out = new(time, job.output, job.at)
|
if job.at and job.at.is_a?(String) and !job.at.empty?
|
||||||
"#{out.time_in_cron_syntax} #{out.task}"
|
ats = job.at.split(',')
|
||||||
|
else
|
||||||
|
ats = [job.at]
|
||||||
|
end
|
||||||
|
|
||||||
|
ats.each do |at|
|
||||||
|
out = new(time, job.output, at)
|
||||||
|
yield "#{out.time_in_cron_syntax} #{out.task}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def time_in_cron_syntax
|
def time_in_cron_syntax
|
||||||
|
36
test/output_at_test.rb
Normal file
36
test/output_at_test.rb
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
require File.expand_path(File.dirname(__FILE__) + "/test_helper")
|
||||||
|
|
||||||
|
class OutputAtTest < Test::Unit::TestCase
|
||||||
|
|
||||||
|
context "weekday at a (single) given time" do
|
||||||
|
setup do
|
||||||
|
@output = Whenever.cron \
|
||||||
|
<<-file
|
||||||
|
every "weekday", :at=>'5:02am' do
|
||||||
|
command "blahblah"
|
||||||
|
end
|
||||||
|
file
|
||||||
|
end
|
||||||
|
|
||||||
|
should "output the runner using that path" do
|
||||||
|
assert_match '2 5 * * mon-fri blahblah', @output
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "weekday at a multiple diverse times" do
|
||||||
|
setup do
|
||||||
|
@output = Whenever.cron \
|
||||||
|
<<-file
|
||||||
|
every "weekday", :at=>'5:02am, 3:52pm' do
|
||||||
|
command "blahblah"
|
||||||
|
end
|
||||||
|
file
|
||||||
|
end
|
||||||
|
|
||||||
|
should "output the runner using that path" do
|
||||||
|
assert_match '2 5 * * mon-fri blahblah', @output
|
||||||
|
assert_match '52 15 * * mon-fri blahblah', @output
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user