Class: SagaForge::RetentionJob

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
lib/saga_forge/retention_job.rb

Overview

Prunes processed events past retention — but only for sagas already finalized: active sagas derive compensation from their history (§A.6). Finalized-ness is the persisted saga_forge_states.finalized_at, stamped atomically at commit (no constantize — robust to a since-deleted saga class, which used to leak those rows past retention forever).

Constant Summary collapse

CONCURRENCY_KEY =

See ExecutionJob::CONCURRENCY_KEY for why this is a constant.

"SagaForge::Retention"
BATCH_SIZE =
500

Instance Method Summary collapse

Instance Method Details

#performObject



19
20
21
22
23
24
25
26
# File 'lib/saga_forge/retention_job.rb', line 19

def perform
  cutoff = SagaForge.config.retention.ago
  scope = Event.processed.where(last_processed_at: ..cutoff)
    .left_joins(:state)
    .where("saga_forge_states.id IS NULL OR saga_forge_states.finalized_at IS NOT NULL")

  scope.in_batches(of: BATCH_SIZE) { |batch| batch.delete_all }
end