Class: CustomerCreditSyncWorker
- Inherits:
-
Object
- Object
- CustomerCreditSyncWorker
- Includes:
- Sidekiq::IterableJob, Sidekiq::Job
- Defined in:
- app/workers/customer_credit_sync_worker.rb
Overview
Recomputes each customer's available credit from their credit limit and
locked credit. Scheduled nightly as synchronize_credit_limits
(config/sidekiq_production_schedule.yml); can also be invoked with a specific
set of customer ids for a targeted re-sync.
Uses Sidekiq::IterableJob so progress is checkpointed after every customer —
a mid-run deploy or worker restart resumes from the last processed customer
instead of re-sweeping the whole table from scratch. CustomerFinancials#sync_credit_limit
is a pure recompute (no external calls), so re-processing a customer on resume
is idempotent.
Instance Method Summary collapse
-
#build_enumerator(customer_ids = [], cursor:) ⇒ Enumerator
Build the resumable enumerator over customers to sync.
- #each_iteration(customer, *_args) ⇒ void
- #on_complete ⇒ Object
Instance Method Details
#build_enumerator(customer_ids = [], cursor:) ⇒ Enumerator
Build the resumable enumerator over customers to sync.
29 30 31 32 33 |
# File 'app/workers/customer_credit_sync_worker.rb', line 29 def build_enumerator(customer_ids = [], cursor:) scope = Customer.where(Customer[:credit_limit].gt(0)) scope = scope.where(id: customer_ids) if customer_ids.present? active_record_records_enumerator(scope, cursor: cursor) end |
#each_iteration(customer, *_args) ⇒ void
This method returns an undefined value.
39 40 41 42 |
# File 'app/workers/customer_credit_sync_worker.rb', line 39 def each_iteration(customer, *_args) customer.sync_credit_limit @synced_count = @synced_count.to_i + 1 end |
#on_complete ⇒ Object
44 45 46 |
# File 'app/workers/customer_credit_sync_worker.rb', line 44 def on_complete Rails.logger.info("[CustomerCreditSyncWorker] Synced credit for #{@synced_count.to_i} customer(s) this run") end |