mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Misc
This commit is contained in:
parent
26d9a92a6b
commit
726b6cad7b
6 changed files with 105 additions and 0 deletions
0
Changes.md
Normal file
0
Changes.md
Normal file
0
LICENSE
Normal file
0
LICENSE
Normal file
12
bin/sidekiq
Executable file
12
bin/sidekiq
Executable file
|
@ -0,0 +1,12 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require 'sidekiq/cli'
|
||||
|
||||
begin
|
||||
cli = Sidekiq::CLI.new ARGV
|
||||
cli.run
|
||||
rescue => e
|
||||
raise e if $DEBUG
|
||||
STDERR.puts e.message
|
||||
exit 1
|
||||
end
|
0
lib/sidekiq.rb
Normal file
0
lib/sidekiq.rb
Normal file
84
lib/sidekiq/cli.rb
Normal file
84
lib/sidekiq/cli.rb
Normal file
|
@ -0,0 +1,84 @@
|
|||
require 'optparse'
|
||||
|
||||
module Sidekiq
|
||||
class CLI
|
||||
def initialize
|
||||
parse_options
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def run
|
||||
write_pid
|
||||
|
||||
server = Sidekiq::Server.new(@options[:server], @options)
|
||||
begin
|
||||
log 'Starting processing, hit Ctrl-C to stop'
|
||||
server.run.join
|
||||
rescue Interrupt
|
||||
log 'Shutting down...'
|
||||
server.stop
|
||||
log '...bye!'
|
||||
end
|
||||
end
|
||||
|
||||
def log(str)
|
||||
STDOUT.puts str
|
||||
end
|
||||
|
||||
def error(str)
|
||||
@STDERR.puts "ERROR: #{str}"
|
||||
end
|
||||
|
||||
def parse_options(argv=ARGV)
|
||||
@options = {
|
||||
:quiet => false,
|
||||
:queues => [],
|
||||
:worker_threads => 25,
|
||||
:location => 'localhost:6379'
|
||||
}
|
||||
|
||||
@parser = OptionParser.new do |o|
|
||||
o.on "-q", "--queue QUEUE", "Queue to process" do |arg|
|
||||
@options[:queues].concat arg.split(",")
|
||||
end
|
||||
|
||||
o.on "-C", "--config PATH", "Load PATH as a config file" do |arg|
|
||||
@options[:config_file] = arg
|
||||
end
|
||||
|
||||
o.on "--pidfile PATH", "Use PATH as a pidfile" do |arg|
|
||||
@options[:pidfile] = arg
|
||||
end
|
||||
|
||||
o.on "-q", "--quiet", "Quiet down the output" do
|
||||
@options[:quiet] = true
|
||||
end
|
||||
|
||||
o.on "-s", "--server LOCATION", "Where to find the server" do |arg|
|
||||
@options[:server] = arg
|
||||
end
|
||||
|
||||
o.on '-t', '--threads INT', "worker threads to use" do |arg|
|
||||
@options[:worker_threads] = arg.to_i
|
||||
end
|
||||
end
|
||||
|
||||
@parser.banner = "sidekiq <options>"
|
||||
@parser.on_tail "-h", "--help", "Show help" do
|
||||
log @parser
|
||||
exit 1
|
||||
end
|
||||
@parser.parse!(argv)
|
||||
end
|
||||
|
||||
def write_pid
|
||||
if path = @options[:pidfile]
|
||||
File.open(path, "w") do |f|
|
||||
f.puts Process.pid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
9
lib/sidekiq/server.rb
Normal file
9
lib/sidekiq/server.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
module Sidekiq
|
||||
|
||||
##
|
||||
# Represents a connection to our MQ server.
|
||||
#
|
||||
class Server
|
||||
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue