1
0
Fork 0
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:
Tobias Svensson 2013-09-17 14:00:10 +01:00
parent 812d3f2469
commit 1cc2165ad5
7 changed files with 35 additions and 17 deletions

View file

@ -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
View 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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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