Sha256: 566ebfd4d0b457bf74d1ccdcc0d489605630221d09b654ae622b8d56d13b9275
Contents?: true
Size: 1.01 KB
Versions: 2
Compression:
Stored size: 1.01 KB
Contents
# frozen_string_literal: true module Totoro class BaseWorker def initialize @prefix = :default Rails.logger = @logger = Logger.new STDOUT @logger.level = Logger.const_get( Rails.configuration.log_level.to_s.upcase ) setup @queue_class = queue_class end def execute @queue_class.subscribe(@queue_name) do |delivery_info, metadata, payload| @logger.info "#{@queue_name} Received: #{payload}" payload_hash = JSON.parse(payload).with_indifferent_access process(payload_hash, metadata, delivery_info) end @logger.info 'Listening to the Rabbitmq' @queue_class.channel.work_pool.join end def process; end private def setup raise(Totoro::NeedQueueNameError, 'Need setup @queue_name') end def queue_class if @prefix == :default Totoro::Queue else "Totoro::#{@prefix.to_s.camelize}::Queue".constantize end end end class NeedQueueNameError < RuntimeError; end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
totoro-0.2.0 | lib/totoro/base_worker.rb |
totoro-0.1.6 | lib/totoro/base_worker.rb |