Class: Cosmo::ActiveJobAdapter::Adapter
- Inherits:
-
Object
- Object
- Cosmo::ActiveJobAdapter::Adapter
- Defined in:
- lib/cosmo/active_job/adapter.rb,
sig/cosmo/active_job/adapter.rbs
Overview
ActiveJob queue adapter that enqueues jobs via NATS JetStream.
Usage:
config.active_job.queue_adapter = :cosmonats
# or explicitly:
config.active_job.queue_adapter = Cosmo::ActiveJobAdapter::Adapter.new
The ActiveJob queue name maps directly to the Cosmo stream name.
Instance Method Summary collapse
-
#enqueue(job) ⇒ String
Enqueue a job to be run as soon as possible.
-
#enqueue_at(job, timestamp) ⇒ String
Enqueue a job to be run at (or after) a given time.
-
#job_cosmo_options(job) ⇒ Hash[Symbol, untyped]
Returns Cosmo-specific options declared on the job class via
cosmo_options, falling back to an empty hash. - #publish(job, timestamp) ⇒ String
Instance Method Details
#enqueue(job) ⇒ String
Enqueue a job to be run as soon as possible.
16 17 18 |
# File 'lib/cosmo/active_job/adapter.rb', line 16 def enqueue(job) publish(job, nil) end |
#enqueue_at(job, timestamp) ⇒ String
Enqueue a job to be run at (or after) a given time.
23 24 25 |
# File 'lib/cosmo/active_job/adapter.rb', line 23 def enqueue_at(job, ) publish(job, ) end |
#job_cosmo_options(job) ⇒ Hash[Symbol, untyped]
Returns Cosmo-specific options declared on the job class via
cosmo_options, falling back to an empty hash.
41 42 43 |
# File 'lib/cosmo/active_job/adapter.rb', line 41 def (job) job.class.respond_to?(:get_cosmo_options) ? job.class. : {} end |
#publish(job, timestamp) ⇒ String
29 30 31 32 33 34 35 36 37 |
# File 'lib/cosmo/active_job/adapter.rb', line 29 def publish(job, ) cosmo_opts = (job) stream = cosmo_opts.delete(:stream) || job.queue_name.to_sym = { stream: stream }.merge(cosmo_opts) [:at] = if data = Job::Data.new(Executor.name, [job.serialize], ) Publisher.publish_job(data) end |