mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
A couple of random small code cleanups
This commit is contained in:
parent
cd2be18a8f
commit
34fe914946
4 changed files with 12 additions and 17 deletions
|
@ -43,7 +43,7 @@ module Sidekiq
|
|||
sigs = %w[INT TERM TTIN TSTP]
|
||||
sigs.each do |sig|
|
||||
trap sig do
|
||||
self_write.write("#{sig}\n")
|
||||
self_write.puts(sig)
|
||||
end
|
||||
rescue ArgumentError
|
||||
puts "Signal #{sig} not supported"
|
||||
|
@ -162,15 +162,12 @@ module Sidekiq
|
|||
end
|
||||
},
|
||||
}
|
||||
UNHANDLED_SIGNAL_HANDLER = ->(cli) { Sidekiq.logger.info "No signal handler registered, ignoring" }
|
||||
SIGNAL_HANDLERS.default = UNHANDLED_SIGNAL_HANDLER
|
||||
|
||||
def handle_signal(sig)
|
||||
Sidekiq.logger.debug "Got #{sig} signal"
|
||||
handy = SIGNAL_HANDLERS[sig]
|
||||
if handy
|
||||
handy.call(self)
|
||||
else
|
||||
Sidekiq.logger.info { "No signal handler for #{sig}" }
|
||||
end
|
||||
SIGNAL_HANDLERS[sig].call(self)
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -204,7 +201,7 @@ module Sidekiq
|
|||
|
||||
# check config file presence
|
||||
if opts[:config_file]
|
||||
if opts[:config_file] && !File.exist?(opts[:config_file])
|
||||
unless File.exist?(opts[:config_file])
|
||||
raise ArgumentError, "No such file #{opts[:config_file]}"
|
||||
end
|
||||
else
|
||||
|
@ -224,7 +221,7 @@ module Sidekiq
|
|||
opts = parse_config(opts[:config_file]).merge(opts) if opts[:config_file]
|
||||
|
||||
# set defaults
|
||||
opts[:queues] = Array(opts[:queues]) << "default" if opts[:queues].nil? || opts[:queues].empty?
|
||||
opts[:queues] = ["default"] if opts[:queues].nil? || opts[:queues].empty?
|
||||
opts[:strict] = true if opts[:strict].nil?
|
||||
opts[:concurrency] = Integer(ENV["RAILS_MAX_THREADS"]) if opts[:concurrency].nil? && ENV["RAILS_MAX_THREADS"]
|
||||
|
||||
|
|
|
@ -129,15 +129,13 @@ module Sidekiq
|
|||
fails = procd = 0
|
||||
|
||||
_, exists, _, _, msg = Sidekiq.redis { |conn|
|
||||
res = conn.multi {
|
||||
conn.multi {
|
||||
conn.sadd("processes", key)
|
||||
conn.exists(key)
|
||||
conn.hmset(key, "info", to_json, "busy", curstate.size, "beat", Time.now.to_f, "quiet", @done)
|
||||
conn.expire(key, 60)
|
||||
conn.rpop("#{key}-signals")
|
||||
}
|
||||
|
||||
res
|
||||
}
|
||||
|
||||
# first heartbeat or recovering from an outage and need to reestablish our heartbeat
|
||||
|
|
|
@ -171,9 +171,9 @@ module Sidekiq
|
|||
now = Time.now.to_f
|
||||
ts = (int < 1_000_000_000 ? now + int : int)
|
||||
|
||||
payload = @opts.merge("class" => @klass, "args" => args, "at" => ts)
|
||||
payload = @opts.merge("class" => @klass, "args" => args)
|
||||
# Optimization to enqueue something now that is scheduled to go out now or in the past
|
||||
payload.delete("at") if ts <= now
|
||||
payload["at"] = ts if ts > now
|
||||
@klass.client_push(payload)
|
||||
end
|
||||
alias_method :perform_at, :perform_in
|
||||
|
@ -207,10 +207,10 @@ module Sidekiq
|
|||
now = Time.now.to_f
|
||||
ts = (int < 1_000_000_000 ? now + int : int)
|
||||
|
||||
item = {"class" => self, "args" => args, "at" => ts}
|
||||
item = {"class" => self, "args" => args}
|
||||
|
||||
# Optimization to enqueue something now that is scheduled to go out now or in the past
|
||||
item.delete("at") if ts <= now
|
||||
item["at"] = ts if ts > now
|
||||
|
||||
client_push(item)
|
||||
end
|
||||
|
|
|
@ -366,7 +366,7 @@ describe Sidekiq::CLI do
|
|||
subject.handle_signal('UNKNOWN')
|
||||
|
||||
assert_match(/Got UNKNOWN signal/, logdev.string)
|
||||
assert_match(/No signal handler for UNKNOWN/, logdev.string)
|
||||
assert_match(/No signal handler registered/, logdev.string)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue