Skip to content

Commit

Permalink
Make timeout a paremeter.
Browse files Browse the repository at this point in the history
  • Loading branch information
eugenk committed May 11, 2016
1 parent f5bf00c commit 7d8bc0c
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions bin/sidekiq_wrapper_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,34 @@

RAILS_ROOT = File.expand_path('../..', __FILE__).freeze
SIDEKIQ_EXECUTABLE = File.join(RAILS_ROOT, 'bin/sidekiq').freeze
SIDEKIQ_BASE_ARGUMENTS = %W(#{SIDEKIQ_EXECUTABLE}
--environment #{ENV['RAILS_ENV'] || 'production'}
--timeout 15).freeze
SIDEKIQ_BASE_ARGUMENTS =
%W(#{SIDEKIQ_EXECUTABLE}
--environment #{ENV['RAILS_ENV'] || 'production'}).freeze

# Parse options
def parse_options(filename)
options = {}
options = {workdir: Dir.pwd,
timeout: 15}
OptionParser.new do |opts|
opts.banner = "Usage: #{filename} [options]"

opts.on('-wMANDATORY', '--workdir=MANDATORY', 'Set work directory') do |w|
opts.on('-wMANDATORY', '--workdir=MANDATORY',
'Set work directory (default: CWD)') do |w|
options[:workdir] = w
end

opts.on('-tMANDATORY', '--timeout=MANDATORY',
'Set timeout in seconds until sidekiq jobs are killed at '\
"sidekiq shutdown (default: #{options[:timeout]})") do |t|
options[:timeout] = t
end
end.parse!
options[:workdir] ||= Dir.pwd
options
end

def run_process(options, arguments, name)
Kernel.exec(*SIDEKIQ_BASE_ARGUMENTS, *arguments,
'--timeout', options[:timeout].to_s,
'--pidfile', "#{File.join(options[:workdir], name)}.pid",
'--logfile', "#{File.join(options[:workdir], name)}.log")
end

0 comments on commit 7d8bc0c

Please sign in to comment.