Class: Cyclid::API::Plugins::Local
- Inherits:
-
Dispatcher
- Object
- Base
- Dispatcher
- Cyclid::API::Plugins::Local
- Extended by:
- Health::Helpers
- Defined in:
- app/cyclid/plugins/dispatcher/local.rb
Overview
Local Sidekiq based dispatcher
Constant Summary
Constants included from Health::Helpers
Class Method Summary collapse
-
.status ⇒ Object
Perform a health check; for this plugin that means:.
Instance Method Summary collapse
-
#dispatch(job, record, callback = nil) ⇒ Object
Queue the job to be run asynchronously.
Methods included from Health::Helpers
Methods inherited from Dispatcher
Methods inherited from Base
config?, config_schema, default_config, get_config, human_name, register_plugin, set_config, update_config
Class Method Details
.status ⇒ Object
Perform a health check; for this plugin that means:
Is Sidekiq running? Is the queue size healthy?
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/cyclid/plugins/dispatcher/local.rb', line 56 def self.status stats = Sidekiq::Stats.new if stats.processes_size.zero? health_status(:error, 'no Sidekiq process is running') elsif stats.enqueued > 10 health_status(:warning, "Sidekiq queue length is too high: #{stats.enqueued}") elsif stats.default_queue_latency > 60 health_status(:warning, "Sidekiq queue latency is too high: #{stats.default_queue_latency}") else health_status(:ok, 'sidekiq is okay') end end |
Instance Method Details
#dispatch(job, record, callback = nil) ⇒ Object
Queue the job to be run asynchronously.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/cyclid/plugins/dispatcher/local.rb', line 27 def dispatch(job, record, callback = nil) Cyclid.logger.debug "dispatching job: #{job}" job_definition = job.to_hash.to_json record.job_name = job.name record.job_version = job.version record.job = job_definition record.save! # The callback instance has to be serailised into JSON to survive the # trip through Redis to Sidekiq callback_json = callback.nil? ? nil : Oj.dump(callback) # Create a SideKiq worker and pass in the job Worker::Local.perform_async(job_definition, record.id, callback_json) # The JobRecord ID is as good a job identifier as anything return record.id end |