New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add sidekiq wrappers. #1689
base: staging
Are you sure you want to change the base?
Add sidekiq wrappers. #1689
Conversation
|
||
RAILS_ROOT = File.expand_path('../..', __FILE__) | ||
SIDEKIQ_EXECUTABLE = File.join(RAILS_ROOT, 'bin/sidekiq') | ||
SIDEKIQ_BASE_ARGUMENTS = %W(#{SIDEKIQ_EXECUTABLE} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Freeze mutable objects assigned to constants.
Oh, and feel free to create a patch on the deployed instances to make a more specific shebang line, as you did with |
OptionParser.new do |opts| | ||
opts.banner = "Usage: #{filename} [options]" | ||
|
||
opts.on('-wMANDATORY', '--workdir=MANDATORY', 'Set work directory') do |w| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
making options mandatory is almost in any case bad design. Use CDW if not given.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done with f5bf00c
Don't understand, why there need to be 3 files for the same? purpose. |
SIDEKIQ_EXECUTABLE = File.join(RAILS_ROOT, 'bin/sidekiq').freeze | ||
SIDEKIQ_BASE_ARGUMENTS = | ||
%W(#{SIDEKIQ_EXECUTABLE} | ||
--environment #{ENV['RAILS_ENV'] || 'production'}).freeze |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Align the elements of an array literal if they span more than one line.
7d8bc0c
to
5798b5c
Compare
We need three different sidekiq instances each with different parameters. For each of these instances, I created a wrapper so that the init script can be very short. The wrappers are subject to change because the parameters may need some tweaking in the future (queue priorities, concurrency).
Done with 5798b5c |
All three sidekiq instances need to be started in parallel. |
No - this is a no go. This way the application logic is pushed back to the starter script which is wrong, buys us nothing (especially because Linux has no contract filesystem for processes). As said, the init script starts one process and this one does, whatever is needed and daemonizes itself. It should provide required flexibility by accepting related options (if not given, choose reasonable defaults). And this one is the one where to send the signals. It than can intercept, xlate or broadcast to forked children or do whatever the documentation says ;-) BTW: Since all the files do more or less the same, have the same purpose, they belong IMHO into a single file. See it as a Starter class, which has certain properties/different starter methods ... |
Alright, now there's only one wrapper to start and stop all instances of sidekiq. It delegates the above-mentioned signals to them. |
Okidoki, I'll try it ... :) |
"Set Rails environment (default: #{options[:environment]})") do |e| | ||
options[:environment] = e | ||
end | ||
|
||
opts.on('-wMANDATORY', '--workdir=MANDATORY', | ||
'Set work directory (default: CWD)') do |w| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW: dict lookup MANDATORY!
Also as a general rule of thumb: In synopsis, usage infos the option value names should indicate its "type", e.g. -w directory, -t seconds. The description should just include '(mandatory)' or '(optional)' if needed. Usually it is not, because the default value should be mentioned and than it is clear, that it is 'optional'. For arg-less options the name option indicates, that it is _option_al and thus doesn't need to be explicitly mentioned. So only in very rare cases or combination of options may require, that 'mandatory' appears in documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The MANDATORY
is Ruby's optparse
's way to say that if -w
is used, then a value must be specified. This does not say that you have to use -w
at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Admins usually have no notion of ill/senseless optparse documentation. However, they know [indirectly] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html by reading man pages and usage synopsis from native Unix utilities ...
The service (i.e. sidekiq_wrapper) does not daemonize itself, but every service always should after it has validated config[s] and runability (started needed workers) successfully. If not, it should exit wqith a proper exit code, which let the "restarter" determine, whether it makes sense to try to restart, whether there is a general error (e.g. missing disk ;-)) or config error (and thus needs to inform the user), etc.. Something like http://daemons.rubyforge.org/Daemonize.html may help ... ? |
Okay. I will implement it, but not today. Preumably on tuesday. |
181fad7
to
2a5c102
Compare
You can now daemonise the process with a separate script (here with all parameters exemplary specified):
This script calls |
Oh, and the daemon process puts a pidfile of itself to |
We need to wait for spechub/Hets#1644 to get this running. |
2641319
to
28f711f
Compare
@jelmd: spechub/Hets#1644 has been merged, so with the next version of Hets, you can specify a pidfile with |
28f711f
to
0f4089c
Compare
These are the most lightweight Sidekiq wrappers I can create.
They create a pid file and a log file in the Workdir. The pid file is actually needed for the executable
bin/sidekiqctl
. It listens to the signalsTERM
to terminate after at most 15 seconds (timeout parameter)USR1
to terminate as soon as all running jobs have been processedUSR2
to reopen the log fileas described in the corresponding Sidekiq wiki page
On my laptop,
sidekiq_hets
takes 0.5 seconds to start up while the other two take 0.006 seconds to start up (i.e. to get to theexec
command).This is already deployed on tc.
This pull request is part of #1646.