Class: IdempotencyCheck::ActiveJobSnapshot

Inherits:
Object
  • Object
show all
Defined in:
lib/idempotency_check/active_job_snapshot.rb

Overview

Snapshots job activity so far (cumulative since the last reset!), broken down by job class and arguments so that swapping which job/args ran between runs is caught, not just a raw count. Covers both:

- enqueued jobs (perform_later), via ActiveJob's :test queue adapter
- performed jobs (perform_now), via ActiveJobPerformTracker

Requires ActiveJob::Base.queue_adapter = :test in the host app.

Class Method Summary collapse

Class Method Details

.reset!Object



18
19
20
21
# File 'lib/idempotency_check/active_job_snapshot.rb', line 18

def self.reset!
  ActiveJob::Base.queue_adapter.enqueued_jobs.clear
  ActiveJobPerformTracker.reset!
end

.takeObject



11
12
13
14
15
16
# File 'lib/idempotency_check/active_job_snapshot.rb', line 11

def self.take
  {
    enqueued: ActiveJob::Base.queue_adapter.enqueued_jobs.map { |job| [job[:job].name, job[:args]] },
    performed: ActiveJobPerformTracker.performed.dup
  }
end