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 = {})
11
11
@mailto = options . fetch ( :mailto , :default_mailto )
12
12
@job_template = options . delete ( :job_template ) || ":job"
13
13
@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 : ''
15
15
@options [ :environment_variable ] ||= "RAILS_ENV"
16
16
@options [ :environment ] ||= :production
17
17
@options [ :path ] = Shellwords . shellescape ( @options [ :path ] || Whenever . path )
Original file line number Diff line number Diff line change 1
1
module Whenever
2
2
module Output
3
3
class Redirection
4
- def initialize ( output )
4
+ def initialize ( output , task )
5
5
@output = output
6
+ @task = task
6
7
end
7
8
8
9
def to_s
@@ -11,7 +12,7 @@ def to_s
11
12
when String then redirect_from_string
12
13
when Hash then redirect_from_hash
13
14
when NilClass then ">> /dev/null 2>&1"
14
- when Proc then @output . call
15
+ when Proc then @output . lambda? ? @output . call : @output . call ( @task )
15
16
else ''
16
17
end
17
18
end
Original file line number Diff line number Diff line change @@ -245,4 +245,20 @@ class OutputRedirectionTest < Whenever::TestCase
245
245
246
246
assert_match ( /^.+ .+ .+ .+ blahblah 2>&1 | logger -t whenever_cron$/ , output )
247
247
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
248
264
end
You can’t perform that action at this time.
0 commit comments