File tree Expand file tree Collapse file tree 3 files changed +20
-3
lines changed
Expand file tree Collapse file tree 3 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ def initialize(options = {})
1111 @mailto = options . fetch ( :mailto , :default_mailto )
1212 @job_template = options . delete ( :job_template ) || ":job"
1313 @roles = Array ( options . delete ( :roles ) )
14- @options [ :output ] = options . has_key? ( :output ) ? Whenever ::Output ::Redirection . new ( options [ :output ] ) . to_s : ''
14+ @options [ :output ] = options . has_key? ( :output ) ? Whenever ::Output ::Redirection . new ( options [ :output ] , options [ :task ] ) . to_s : ''
1515 @options [ :environment_variable ] ||= "RAILS_ENV"
1616 @options [ :environment ] ||= :production
1717 @options [ :path ] = Shellwords . shellescape ( @options [ :path ] || Whenever . path )
Original file line number Diff line number Diff line change 11module Whenever
22 module Output
33 class Redirection
4- def initialize ( output )
4+ def initialize ( output , task )
55 @output = output
6+ @task = task
67 end
78
89 def to_s
@@ -11,7 +12,7 @@ def to_s
1112 when String then redirect_from_string
1213 when Hash then redirect_from_hash
1314 when NilClass then ">> /dev/null 2>&1"
14- when Proc then @output . call
15+ when Proc then @output . lambda? ? @output . call : @output . call ( @task )
1516 else ''
1617 end
1718 end
Original file line number Diff line number Diff line change @@ -245,4 +245,20 @@ class OutputRedirectionTest < Whenever::TestCase
245245
246246 assert_match ( /^.+ .+ .+ .+ blahblah 2>&1 | logger -t whenever_cron$/ , output )
247247 end
248+
249+ test 'a command when the standard output is set to a proc' do
250+ output = Whenever . cron \
251+ <<-file
252+ # :output must be escaped so that eval can be executed
253+ set :job_template, nil
254+ set :output, proc { |task| "2>&1 | " + task.sub(/\\ ..+$/, '') + ".log" }
255+ every 2.hours do
256+ command "/path/to/file_a.rb"
257+ command "/path/to/file_b"
258+ end
259+ file
260+
261+ assert_match ( %r{^.+ .+ .+ .+ /path/to/file_a.rb 2>&1 | /path/to/file_a.log$} , output )
262+ assert_match ( %r{^.+ .+ .+ .+ /path/to/file_b 2>&1 | /path/to/file_b.log$} , output )
263+ end
248264end
You can’t perform that action at this time.
0 commit comments