Module: Cuniculus
- Extended by:
- CuniculusMethods
- Defined in:
- lib/cuniculus.rb,
lib/cuniculus/cli.rb,
lib/cuniculus/core.rb,
lib/cuniculus/config.rb,
lib/cuniculus/logger.rb,
lib/cuniculus/worker.rb,
lib/cuniculus/plugins.rb,
lib/cuniculus/version.rb,
lib/cuniculus/consumer.rb,
lib/cuniculus/job_queue.rb,
lib/cuniculus/dispatcher.rb,
lib/cuniculus/exceptions.rb,
lib/cuniculus/pub_worker.rb,
lib/cuniculus/supervisor.rb,
lib/cuniculus/queue_config.rb,
lib/cuniculus/plugins/health_check.rb
Overview
Base definition of the Cuniculus Module
Defined Under Namespace
Modules: CuniculusMethods, Plugins, SupervisorMethods, Worker Classes: CLI, Config, Consumer, Dispatcher, Error, JobQueue, Logger, PubWorker, QueueConfig, Supervisor
Constant Summary collapse
- CUNICULUS_EXCHANGE =
"cuniculus"
- CUNICULUS_DLX_EXCHANGE =
Dead Letter Exchange
"cuniculus_dlx"
- MAJOR =
The major version of Cuniculus. Only bumped for major changes.
0
- MINOR =
The minor version of Cuniculus. Bumped for every non-patch level release.
2
- TINY =
The tiny version of Cuniculus. Usually 0, only bumped for bugfix releases that fix regressions from previous versions.
1
- VERSION =
The version of Cuniculus you are using, as a string (e.g. “2.11.0”)
[MAJOR, MINOR, TINY].join(".").freeze
- VERSION_NUMBER =
The version of Cuniculus you are using, as a number (2.11.0 -> 20110)
MAJOR * 10_000 + MINOR * 10 + TINY
Class Method Summary collapse
-
.config ⇒ Cuniculus::Config
Current config of Cuniculus.
-
.configure {|Cuniculus::Config| ... } ⇒ Object
Configure Cuniculus.
- .dispatcher ⇒ Object
- .enqueue(job) ⇒ Object
-
.error_handler(&block) ⇒ Object
Receives a block that is called when the job consumer encounters an error.
-
.logger ⇒ Cuniculus::Logger
Current Cuniculus logger.
-
.plugin(plugin, *args, &block) ⇒ Object
Load a plugin.
- .shutdown ⇒ Object
-
.version ⇒ Object
The version of Cuniculus you are using, as a string (e.g. “2.11.0”).
Methods included from CuniculusMethods
convert_exception_class, dump_job, load_job, mark_time
Class Method Details
.config ⇒ Cuniculus::Config
Current config of Cuniculus
Returns config for read-only purpose. Use Cuniculus.configure to change the configured values.
52 53 54 |
# File 'lib/cuniculus.rb', line 52 def self.config @config ||= Cuniculus::Config.new end |
.configure {|Cuniculus::Config| ... } ⇒ Object
Configure Cuniculus. Check Config for the available options.
26 27 28 29 30 31 32 |
# File 'lib/cuniculus.rb', line 26 def self.configure cfg = Cuniculus::Config.new yield cfg cfg.declare! @config = cfg @dispatcher = Cuniculus::Dispatcher.new(cfg) end |
.dispatcher ⇒ Object
43 44 45 |
# File 'lib/cuniculus.rb', line 43 def self.dispatcher @dispatcher ||= Cuniculus::Dispatcher.new(config) end |
.enqueue(job) ⇒ Object
34 35 36 37 |
# File 'lib/cuniculus.rb', line 34 def self.enqueue(job) dispatcher.job_queue << job dispatcher.start! end |
.error_handler(&block) ⇒ Object
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.
77 78 79 80 81 82 83 |
# File 'lib/cuniculus.rb', line 77 def self.error_handler(&block) Cuniculus::Consumer.define_method(:handle_error, &block) Cuniculus::Consumer.instance_eval { private :handle_error } Cuniculus::Dispatcher.define_method(:handle_error, &block) Cuniculus::Dispatcher.instance_eval { private :handle_error } end |
.logger ⇒ Cuniculus::Logger
Current Cuniculus logger
59 60 61 |
# File 'lib/cuniculus.rb', line 59 def self.logger @logger ||= Cuniculus::Logger.new($stdout, level: Logger::INFO) end |
.plugin(plugin, *args, &block) ⇒ Object
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.
98 99 100 101 102 103 104 105 |
# File 'lib/cuniculus.rb', line 98 def self.plugin(plugin, *args, &block) plugin = Cuniculus::Plugins.load_plugin(plugin) if plugin.is_a?(Symbol) raise Cuniculus::Error, "Invalid plugin type: #{plugin.class.inspect}. It must be a module" unless plugin.is_a?(Module) self::Supervisor.send(:include, plugin::SupervisorMethods) if defined?(plugin::SupervisorMethods) self::Supervisor.send(:extend, plugin::SupervisorClassMethods) if defined?(plugin::SupervisorClassMethods) plugin.configure(config.opts, *args, &block) if plugin.respond_to?(:configure) end |
.shutdown ⇒ Object
39 40 41 |
# File 'lib/cuniculus.rb', line 39 def self.shutdown dispatcher.shutdown end |
.version ⇒ Object
The version of Cuniculus you are using, as a string (e.g. “2.11.0”)
22 23 24 |
# File 'lib/cuniculus/version.rb', line 22 def self.version VERSION end |