Class: Sidekiq::TrackEnqueuedStatusJobsMiddleware
- Inherits:
-
Object
- Object
- Sidekiq::TrackEnqueuedStatusJobsMiddleware
- Defined in:
- lib/sidekiq/track_enqueued_status_jobs_middleware.rb
Overview
Client middleware that records every status-tracked job (a worker that
includes Sidekiq::Status::Worker, e.g. via Workers::StatusBroadcastable)
enqueued during a CRM web request, so the global Jobs offcanvas can surface
it — even when the enqueuing action redirects somewhere other than
/jobs/:jid (which is the only page that otherwise self-registers a job).
Collection is gated on CurrentScope.enqueued_status_jobs being non-nil.
CrmController initializes it to [] per request; everywhere else (non-CRM
requests, and the Sidekiq server process running jobs) it stays nil, so this
middleware is a cheap no-op outside the CRM web tier.
CrmController#persist_enqueued_status_jobs drains the collector into
flash[:tracked_jobs]; shared/_tracked_jobs.html.erb + the job-bridge Stimulus
controller hand the jids to the job tracker, which polls /jobs/:jid.json.
Registered LAST in the client middleware chain (see
config/initializers/sidekiq.rb) so it only runs when upstream middleware —
notably SidekiqUniqueJobs — actually let the push through. A duplicate that
unique-jobs rejects never reaches here, so rejected jobs are not recorded.
Two opt-outs keep silent/background work out of the panel:
- Class-level — a worker that defines
self.track_in_jobs_panel? => false
is never recorded. For workers whose tracking is never wanted because
the user never initiates them and awaits no result (e.g. the lazy
PartyProfileImageWorker backfill fired on every contact-card render). - Per-site —
CurrentScope.without_job_tracking { Worker.perform_async … }
suppresses just that enqueue. For workers with BOTH a user-initiated path
(toast wanted) and an automatic callback path (toast unwanted), e.g.
PartyEnrichmentWorker: explicit "Enrich" runs still track, lifecycle
auto-enrichment does not.
Constant Summary collapse
- MAX_TRACKED =
Cap how many jobs a single request contributes to the tracker. Bounds the
flash payload carried in the (cache-backed) session, keeps the dedup scan
below cheap, and matches what the offcanvas can usefully show. A user
rarely kicks off more than a couple of tracked jobs in one request; a bulk
action that fans out hundreds shows the first 25 and the rest still run. 25
Instance Method Summary collapse
-
#call(_worker_class, job, _queue, _redis_pool) ⇒ Object
Sidekiq client middleware entry point.
Instance Method Details
#call(_worker_class, job, _queue, _redis_pool) ⇒ Object
Sidekiq client middleware entry point. Lets the push proceed, then records
the job for the tracker — recording never alters the enqueue outcome.
50 51 52 53 54 |
# File 'lib/sidekiq/track_enqueued_status_jobs_middleware.rb', line 50 def call(_worker_class, job, _queue, _redis_pool) result = yield record(job) result end |