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
|
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
|
@time = time
|
||||||
@task = task
|
@task = task
|
||||||
@at = at.is_a?(String) ? (Chronic.parse(at) || 0) : (at || 0)
|
@at = at.is_a?(String) ? (Chronic.parse(at) || 0) : (at || 0)
|
||||||
@output_redirection = output_redirection
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.enumerate(item)
|
def self.enumerate(item)
|
||||||
@ -24,13 +23,13 @@ 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).each do |at|
|
||||||
yield new(time, job.output, at, job.output_redirection).output
|
yield new(time, job.output, at).output
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def output
|
def output
|
||||||
[time_in_cron_syntax, task, output_redirection].compact.join(' ').strip
|
[time_in_cron_syntax, task].compact.join(' ').strip
|
||||||
end
|
end
|
||||||
|
|
||||||
def time_in_cron_syntax
|
def time_in_cron_syntax
|
||||||
@ -41,10 +40,6 @@ module Whenever
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def output_redirection
|
|
||||||
Whenever::Output::Cron::OutputRedirection.new(@output_redirection).to_s unless @output_redirection == :not_set
|
|
||||||
end
|
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def parse_symbol
|
def parse_symbol
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
module Whenever
|
module Whenever
|
||||||
class Job
|
class Job
|
||||||
|
|
||||||
attr_reader :at, :output_redirection
|
attr_reader :at
|
||||||
|
|
||||||
def initialize(options = {})
|
def initialize(options = {})
|
||||||
@options = options
|
@options = options
|
||||||
|
|
||||||
@at = options[:at]
|
@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[:environment] ||= :production
|
||||||
@options[:path] ||= Whenever.path
|
@options[:path] ||= Whenever.path
|
||||||
end
|
end
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
job_type :command, ":task"
|
job_type :command, ":task :output"
|
||||||
job_type :runner, "cd :path && script/runner -e :environment ':task'"
|
job_type :runner, "cd :path && script/runner -e :environment ':task' :output"
|
||||||
job_type :rake, "cd :path && RAILS_ENV=:environment rake :task --silent"
|
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)
|
alias_method(:rails2_runner, :runner) if defined?(:runner)
|
||||||
end
|
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
|
end
|
@ -1,7 +1,6 @@
|
|||||||
module Whenever
|
module Whenever
|
||||||
module Output
|
module Output
|
||||||
class Cron
|
class Redirection
|
||||||
class OutputRedirection
|
|
||||||
|
|
||||||
def initialize(output)
|
def initialize(output)
|
||||||
@output = output
|
@output = output
|
||||||
@ -56,5 +55,4 @@ module Whenever
|
|||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
@ -7,14 +7,6 @@ class JobTest < Test::Unit::TestCase
|
|||||||
assert_equal 'foo', new_job(:at => 'foo').at
|
assert_equal 'foo', new_job(:at => 'foo').at
|
||||||
end
|
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
|
should "substitute the :task when #output is called" do
|
||||||
job = new_job(:template => ":task", :task => 'abc123')
|
job = new_job(:template => ":task", :task => 'abc123')
|
||||||
assert_equal 'abc123', job.output
|
assert_equal 'abc123', job.output
|
||||||
|
Loading…
Reference in New Issue
Block a user