module Cuniculus
Base definition of the Cuniculus
Module
Constants
- BadlyFormattedPayload
- CUNICULUS_DLX_EXCHANGE
- CUNICULUS_EXCHANGE
- ConfigError
- MAJOR
The major version of
Cuniculus
. Only bumped for major changes.- MINOR
The minor version of
Cuniculus
. Bumped for every non-patch level release.- RMQConnectionError
- RMQQueueConfigurationConflict
- TINY
The tiny version of
Cuniculus
. Usually 0, only bumped for bugfix releases that fix regressions from previous versions.- VERSION
The version of
Cuniculus
you are using, as a string (e.g. “2.11.0”)- VERSION_NUMBER
The version of
Cuniculus
you are using, as a number (2.11.0 -> 20110)- WorkerOptionsError
Public Class Methods
Current config of Cuniculus
Returns config for read-only purpose. Use {Cuniculus.configure Cuniculus.configure
} to change the configured values.
@return [Cuniculus::Config]
# File lib/cuniculus.rb 52 def self.config 53 @config ||= Cuniculus::Config.new 54 end
Configure Cuniculus
. Check {Cuniculus::Config} for the available options.
@yield [Cuniculus::Config]
@example Change RabbitMQ connection details.
Cuniculus.configure do |cfg| cfg.rabbitmq_opts = { host: 'rmq.mycompany.com', user: 'guest', pass: 'guest' } cfg.add_queue({ name: "new_queue", max_retry: 4 }) end
# File lib/cuniculus.rb 26 def self.configure 27 cfg = Cuniculus::Config.new 28 yield cfg 29 cfg.declare! 30 @config = cfg 31 @dispatcher = Cuniculus::Dispatcher.new(cfg) 32 end
# File lib/cuniculus.rb 43 def self.dispatcher 44 @dispatcher ||= Cuniculus::Dispatcher.new(config) 45 end
# File lib/cuniculus.rb 34 def self.enqueue(job) 35 dispatcher.job_queue << job 36 dispatcher.start! 37 end
Receives a block that is called when the job consumer encounters an error. The block receives the exception object and runs in the context of the consumer instance.
Note that overriding the default error handler does not affect the retry mechanism. This error handler is designed to be used for logging.
The default error handler is defined in {Cuniculus::Consumer#handle_error}.
@example Send error info to an external service.
Cuniculus.error_handler do |e| err = "#{e.class.name}: #{e.message}" bt = e.backtrace.join("\n") unless e.backtrace.nil? MyLogginService.error(err, bt) end
# File lib/cuniculus.rb 77 def self.error_handler(&block) 78 Cuniculus::Consumer.define_method(:handle_error, &block) 79 Cuniculus::Consumer.instance_eval { private :handle_error } 80 81 Cuniculus::Dispatcher.define_method(:handle_error, &block) 82 Cuniculus::Dispatcher.instance_eval { private :handle_error } 83 end
Current Cuniculus
logger
@return [Cuniculus::Logger]
# File lib/cuniculus.rb 59 def self.logger 60 @logger ||= Cuniculus::Logger.new($stdout, level: Logger::INFO) 61 end
Load a plugin. If plugin is a Module, it is loaded directly. If it is a symbol, then it needs to satisfy the following:
-
The call `require “cuniculus/plugins/#{plugin}”` should succeed
-
The required plugin must register itself by calling {Cuniculus::Plugins.register_plugin}
The additional arguments and block are passed to the plugin's `configure` method, if it exists.
@param plugin [Symbol, Module] @param args [Array<Object>] *args passed to the plugin's `configure` method @param [Block] block passed to the plugin's `configure` method
@example Enable `:health_check` plugin
Cuniculus.plugin(:health_check)
# File lib/cuniculus.rb 98 def self.plugin(plugin, *args, &block) 99 plugin = Cuniculus::Plugins.load_plugin(plugin) if plugin.is_a?(Symbol) 100 raise Cuniculus::Error, "Invalid plugin type: #{plugin.class.inspect}. It must be a module" unless plugin.is_a?(Module) 101 102 self::Supervisor.send(:include, plugin::SupervisorMethods) if defined?(plugin::SupervisorMethods) 103 self::Supervisor.send(:extend, plugin::SupervisorClassMethods) if defined?(plugin::SupervisorClassMethods) 104 plugin.configure(config.opts, *args, &block) if plugin.respond_to?(:configure) 105 end
# File lib/cuniculus.rb 39 def self.shutdown 40 dispatcher.shutdown 41 end
The version of Cuniculus
you are using, as a string (e.g. “2.11.0”)
# File lib/cuniculus/version.rb 22 def self.version 23 VERSION 24 end