Module: Railsmith::AsyncEnqueuers
- Defined in:
- lib/railsmith/async_enqueuers.rb
Overview
Small helpers for enqueueing async work across job backends.
The nested-writes feature primarily targets ActiveJob, which in turn can be backed by SolidQueue/SolidJob, GoodJob, DelayedJob, Sidekiq, etc.
For non-ActiveJob systems (e.g. Sneakers), apps can provide ‘Railsmith.configuration.async_enqueuer` and call into their queue client while keeping the same payload contract.
Class Method Summary collapse
-
.active_job(job_class, payload) ⇒ Object
Enqueue via ActiveJob-style ‘.perform_later(**payload)`.
-
.call(enqueuer, job_class, payload) ⇒ Object
Generic enqueue helper for custom systems.
-
.sidekiq(job_class, payload) ⇒ Object
Enqueue via Sidekiq-style ‘.perform_async(payload_hash)`.
Class Method Details
.active_job(job_class, payload) ⇒ Object
Enqueue via ActiveJob-style ‘.perform_later(**payload)`. Returns a job_id when available; otherwise nil.
17 18 19 20 |
# File 'lib/railsmith/async_enqueuers.rb', line 17 def active_job(job_class, payload) job = job_class.perform_later(**payload) job.respond_to?(:job_id) ? job.job_id : nil end |
.call(enqueuer, job_class, payload) ⇒ Object
Generic enqueue helper for custom systems. The default nested-writer code will call this only if you wire it in as ‘config.async_enqueuer`.
31 32 33 34 35 36 37 |
# File 'lib/railsmith/async_enqueuers.rb', line 31 def call(enqueuer, job_class, payload) job_or_id = enqueuer.call(job_class, payload) return job_or_id.job_id if job_or_id.respond_to?(:job_id) return job_or_id if job_or_id.is_a?(String) || job_or_id.is_a?(Integer) nil end |
.sidekiq(job_class, payload) ⇒ Object
Enqueue via Sidekiq-style ‘.perform_async(payload_hash)`. Returns the Sidekiq JID (String) when provided by the backend.
24 25 26 |
# File 'lib/railsmith/async_enqueuers.rb', line 24 def sidekiq(job_class, payload) job_class.perform_async(payload) end |