Send all logs to stderr by default instead of stdout. Fixes a problem where parsing the output of sandboxed commands could fail, because they could contain Rails log messages in their stdout. When we run a command in a sandbox, we call fork+exec to run the command in the background so we can capture its output. If Rails prints anything to stdout between the fork and exec calls, then it will be inadvertently captured along with the command's output. This will break parsing of the command's output. This can happen if warning messages are printed by Rails while setting up the sandbox between the fork and exec calls. Writing to stderr is also more correct, since stdout is buffered by default, which means logs could potentially be lost if the process dies unexpectedly before the buffers are flushed. Stderr is unbuffered by default, which means logs will always be output immediately.
15 lines
429 B
Ruby
15 lines
429 B
Ruby
require 'delayed/plugin'
|
|
|
|
class DelayedJobTimeoutPlugin < ::Delayed::Plugin
|
|
callbacks do |lifecycle|
|
|
lifecycle.before(:execute) do |job|
|
|
Delayed::Job.connection.execute "set statement_timeout = 0"
|
|
end
|
|
end
|
|
end
|
|
|
|
Delayed::Worker.logger = Logger.new(STDERR, level: :debug)
|
|
Delayed::Worker.default_queue_name = "default"
|
|
Delayed::Worker.destroy_failed_jobs = false
|
|
Delayed::Worker.plugins << DelayedJobTimeoutPlugin
|