moved output redirection to the Job class and subing it in from the job templates
This commit is contained in:
parent
4e0c357f4d
commit
953987c6b2
@ -4,11 +4,10 @@ module Whenever
|
||||
|
||||
attr_accessor :time, :task
|
||||
|
||||
def initialize(time = nil, task = nil, at = nil, output_redirection = nil)
|
||||
def initialize(time = nil, task = nil, at = nil)
|
||||
@time = time
|
||||
@task = task
|
||||
@at = at.is_a?(String) ? (Chronic.parse(at) || 0) : (at || 0)
|
||||
@output_redirection = output_redirection
|
||||
end
|
||||
|
||||
def self.enumerate(item)
|
||||
@ -24,13 +23,13 @@ module Whenever
|
||||
def self.output(times, job)
|
||||
enumerate(times).each do |time|
|
||||
enumerate(job.at).each do |at|
|
||||
yield new(time, job.output, at, job.output_redirection).output
|
||||
yield new(time, job.output, at).output
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def output
|
||||
[time_in_cron_syntax, task, output_redirection].compact.join(' ').strip
|
||||
[time_in_cron_syntax, task].compact.join(' ').strip
|
||||
end
|
||||
|
||||
def time_in_cron_syntax
|
||||
@ -41,10 +40,6 @@ module Whenever
|
||||
end
|
||||
end
|
||||
|
||||
def output_redirection
|
||||
Whenever::Output::Cron::OutputRedirection.new(@output_redirection).to_s unless @output_redirection == :not_set
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def parse_symbol
|
||||
|
@ -1,13 +1,13 @@
|
||||
module Whenever
|
||||
class Job
|
||||
|
||||
attr_reader :at, :output_redirection
|
||||
attr_reader :at
|
||||
|
||||
def initialize(options = {})
|
||||
@options = options
|
||||
|
||||
@at = options[:at]
|
||||
@output_redirection = options.has_key?(:output) ? options[:output] : :not_set
|
||||
@options[:output] = Whenever::Output::Redirection.new(options[:output]).to_s if options.has_key?(:output)
|
||||
@options[:environment] ||= :production
|
||||
@options[:path] ||= Whenever.path
|
||||
end
|
||||
|
@ -1,3 +1,3 @@
|
||||
job_type :command, ":task"
|
||||
job_type :runner, "cd :path && script/runner -e :environment ':task'"
|
||||
job_type :rake, "cd :path && RAILS_ENV=:environment rake :task --silent"
|
||||
job_type :command, ":task :output"
|
||||
job_type :runner, "cd :path && script/runner -e :environment ':task' :output"
|
||||
job_type :rake, "cd :path && RAILS_ENV=:environment rake :task --silent :output"
|
||||
|
@ -7,5 +7,5 @@ if File.exists?(File.join(Whenever.path, 'script', 'rails'))
|
||||
alias_method(:rails2_runner, :runner) if defined?(:runner)
|
||||
end
|
||||
|
||||
job_type :runner, "cd :path && script/rails runner -e :environment ':task'"
|
||||
job_type :runner, "cd :path && script/rails runner -e :environment ':task' :output"
|
||||
end
|
@ -1,7 +1,6 @@
|
||||
module Whenever
|
||||
module Output
|
||||
class Cron
|
||||
class OutputRedirection
|
||||
class Redirection
|
||||
|
||||
def initialize(output)
|
||||
@output = output
|
||||
@ -57,4 +56,3 @@ module Whenever
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -7,14 +7,6 @@ class JobTest < Test::Unit::TestCase
|
||||
assert_equal 'foo', new_job(:at => 'foo').at
|
||||
end
|
||||
|
||||
should "return :output when #output_redirection is called" do
|
||||
assert_equal 'foo', new_job(:output => 'foo').output_redirection
|
||||
end
|
||||
|
||||
should "return :not_set when #output_redirection is called and no :output is set" do
|
||||
assert_equal :not_set, new_job.output_redirection
|
||||
end
|
||||
|
||||
should "substitute the :task when #output is called" do
|
||||
job = new_job(:template => ":task", :task => 'abc123')
|
||||
assert_equal 'abc123', job.output
|
||||
|
Loading…
Reference in New Issue
Block a user