diff --git a/lib/sidetiq.rb b/lib/sidetiq.rb index 82a2df6..d50599b 100644 --- a/lib/sidetiq.rb +++ b/lib/sidetiq.rb @@ -24,6 +24,7 @@ require 'sidetiq/version' require 'sidetiq/middleware/history' # actor topology +require 'sidetiq/actor' require 'sidetiq/actor/clock' require 'sidetiq/actor/handler' require 'sidetiq/supervisor' diff --git a/lib/sidetiq/actor.rb b/lib/sidetiq/actor.rb new file mode 100644 index 0000000..7020e2d --- /dev/null +++ b/lib/sidetiq/actor.rb @@ -0,0 +1,18 @@ +module Sidetiq + module Actor + def self.included(base) + base.__send__(:include, Celluloid) + end + + def initialize(*args, &block) + log_call "initialize" + super + end + + private + + def log_call(call) + info "#{self.class.name} id: #{object_id} #{call}" + end + end +end diff --git a/lib/sidetiq/actor/clock.rb b/lib/sidetiq/actor/clock.rb index 3cb6e1c..abc11e2 100644 --- a/lib/sidetiq/actor/clock.rb +++ b/lib/sidetiq/actor/clock.rb @@ -1,12 +1,12 @@ module Sidetiq module Actor class Clock < Sidetiq::Clock - include Celluloid + include Sidetiq::Actor include Sidekiq::ExceptionHandler # Public: Starts the clock loop. def start! - info "Sidetiq::Clock start" + debug "Sidetiq::Clock looping ..." loop! end diff --git a/lib/sidetiq/actor/handler.rb b/lib/sidetiq/actor/handler.rb index f1dfda2..0f8b126 100644 --- a/lib/sidetiq/actor/handler.rb +++ b/lib/sidetiq/actor/handler.rb @@ -1,12 +1,7 @@ module Sidetiq module Actor class Handler < Sidetiq::Handler - include Celluloid - - def initialize - info "Sidetiq::Handler initialize #{object_id}" - super - end + include Sidetiq::Actor end end end diff --git a/lib/sidetiq/config.rb b/lib/sidetiq/config.rb index 4b95848..4a295c7 100644 --- a/lib/sidetiq/config.rb +++ b/lib/sidetiq/config.rb @@ -28,7 +28,7 @@ module Sidetiq config.resolution = 1 config.lock_expire = 1000 config.utc = false - config.handler_pool_size = 5 + config.handler_pool_size = nil end end diff --git a/lib/sidetiq/handler.rb b/lib/sidetiq/handler.rb index add2899..875db36 100644 --- a/lib/sidetiq/handler.rb +++ b/lib/sidetiq/handler.rb @@ -18,6 +18,7 @@ module Sidetiq end rescue StandardError => e handle_exception(e, context: "Sidetiq::Handler#dispatch") + raise e end private @@ -43,6 +44,7 @@ module Sidetiq end rescue StandardError => e handle_exception(e, context: "Sidetiq::Handler#enqueue") + raise e end end end diff --git a/lib/sidetiq/supervisor.rb b/lib/sidetiq/supervisor.rb index c8da306..27d3785 100644 --- a/lib/sidetiq/supervisor.rb +++ b/lib/sidetiq/supervisor.rb @@ -3,9 +3,15 @@ module Sidetiq supervise Sidetiq::Actor::Clock, as: :sidetiq_clock if Sidekiq.server? - pool Sidetiq::Actor::Handler, - as: :sidetiq_handler, - size: Sidetiq.config.handler_pool_size + if handler_pool_size = Sidetiq.config.handler_pool_size + pool Sidetiq::Actor::Handler, + as: :sidetiq_handler, + size: handler_pool_size + else + # Use Celluloid's CPU-based default. + pool Sidetiq::Actor::Handler, + as: :sidetiq_handler + end end class << self @@ -24,15 +30,11 @@ module Sidetiq def run! motd info "Sidetiq::Supervisor start" - super end def run - motd - info "Sidetiq::Supervisor start (foreground)" - - super + raise "Sidetiq::Supervisor should not be run in foreground." end private