mirror of
https://github.com/endofunky/sidetiq.git
synced 2022-11-09 13:53:30 -05:00
Add custom actor mixin.
This commit is contained in:
parent
812d3f2469
commit
1cc2165ad5
7 changed files with 35 additions and 17 deletions
|
@ -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'
|
||||
|
|
18
lib/sidetiq/actor.rb
Normal file
18
lib/sidetiq/actor.rb
Normal file
|
@ -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
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue