class Userlist::Push::Strategies::Threaded::Worker
Constants
- MAX_WORKER_TIMEOUT
Attributes
config[R]
queue[R]
thread[R]
Public Class Methods
new(queue, config = {})
click to toggle source
# File lib/userlist/push/strategies/threaded/worker.rb, line 10 def initialize(queue, config = {}) @queue = queue @config = Userlist.config.merge(config) @thread = Thread.new { run } @thread.abort_on_exception = true end
Public Instance Methods
run()
click to toggle source
# File lib/userlist/push/strategies/threaded/worker.rb, line 17 def run logger.info 'Starting worker thread...' loop do begin method, *args = *queue.pop break if method == :stop client.public_send(method, *args) rescue StandardError => e logger.error "Failed to deliver payload: [#{e.class.name}] #{e.message}" end end logger.info "Worker thread exited with #{queue.size} tasks still in the queue..." end
stop()
click to toggle source
# File lib/userlist/push/strategies/threaded/worker.rb, line 34 def stop logger.info 'Stopping worker thread...' queue.push([:stop]) thread.join(MAX_WORKER_TIMEOUT) end
Private Instance Methods
client()
click to toggle source
# File lib/userlist/push/strategies/threaded/worker.rb, line 44 def client @client ||= Userlist::Push::Client.new(config) end