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'
|
require 'sidetiq/middleware/history'
|
||||||
|
|
||||||
# actor topology
|
# actor topology
|
||||||
|
require 'sidetiq/actor'
|
||||||
require 'sidetiq/actor/clock'
|
require 'sidetiq/actor/clock'
|
||||||
require 'sidetiq/actor/handler'
|
require 'sidetiq/actor/handler'
|
||||||
require 'sidetiq/supervisor'
|
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 Sidetiq
|
||||||
module Actor
|
module Actor
|
||||||
class Clock < Sidetiq::Clock
|
class Clock < Sidetiq::Clock
|
||||||
include Celluloid
|
include Sidetiq::Actor
|
||||||
include Sidekiq::ExceptionHandler
|
include Sidekiq::ExceptionHandler
|
||||||
|
|
||||||
# Public: Starts the clock loop.
|
# Public: Starts the clock loop.
|
||||||
def start!
|
def start!
|
||||||
info "Sidetiq::Clock start"
|
debug "Sidetiq::Clock looping ..."
|
||||||
loop!
|
loop!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,7 @@
|
||||||
module Sidetiq
|
module Sidetiq
|
||||||
module Actor
|
module Actor
|
||||||
class Handler < Sidetiq::Handler
|
class Handler < Sidetiq::Handler
|
||||||
include Celluloid
|
include Sidetiq::Actor
|
||||||
|
|
||||||
def initialize
|
|
||||||
info "Sidetiq::Handler initialize #{object_id}"
|
|
||||||
super
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -28,7 +28,7 @@ module Sidetiq
|
||||||
config.resolution = 1
|
config.resolution = 1
|
||||||
config.lock_expire = 1000
|
config.lock_expire = 1000
|
||||||
config.utc = false
|
config.utc = false
|
||||||
config.handler_pool_size = 5
|
config.handler_pool_size = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ module Sidetiq
|
||||||
end
|
end
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
handle_exception(e, context: "Sidetiq::Handler#dispatch")
|
handle_exception(e, context: "Sidetiq::Handler#dispatch")
|
||||||
|
raise e
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -43,6 +44,7 @@ module Sidetiq
|
||||||
end
|
end
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
handle_exception(e, context: "Sidetiq::Handler#enqueue")
|
handle_exception(e, context: "Sidetiq::Handler#enqueue")
|
||||||
|
raise e
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,9 +3,15 @@ module Sidetiq
|
||||||
supervise Sidetiq::Actor::Clock, as: :sidetiq_clock
|
supervise Sidetiq::Actor::Clock, as: :sidetiq_clock
|
||||||
|
|
||||||
if Sidekiq.server?
|
if Sidekiq.server?
|
||||||
pool Sidetiq::Actor::Handler,
|
if handler_pool_size = Sidetiq.config.handler_pool_size
|
||||||
as: :sidetiq_handler,
|
pool Sidetiq::Actor::Handler,
|
||||||
size: Sidetiq.config.handler_pool_size
|
as: :sidetiq_handler,
|
||||||
|
size: handler_pool_size
|
||||||
|
else
|
||||||
|
# Use Celluloid's CPU-based default.
|
||||||
|
pool Sidetiq::Actor::Handler,
|
||||||
|
as: :sidetiq_handler
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
@ -24,15 +30,11 @@ module Sidetiq
|
||||||
def run!
|
def run!
|
||||||
motd
|
motd
|
||||||
info "Sidetiq::Supervisor start"
|
info "Sidetiq::Supervisor start"
|
||||||
|
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
def run
|
def run
|
||||||
motd
|
raise "Sidetiq::Supervisor should not be run in foreground."
|
||||||
info "Sidetiq::Supervisor start (foreground)"
|
|
||||||
|
|
||||||
super
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue