Class: CounterOperationWorker

Inherits:
ApplicationWorker show all
Defined in:
app/workers/counter_operation_worker.rb

Overview

Worker responsible for performing delayed operations on Counter records to maintain cache consistency and prevent race conditions when updating counter caches asynchronously.

Instance Method Summary collapse

Methods inherited from ApplicationWorker

unlimited_retry

Instance Method Details

#perform(operation, counter_id, value = nil) ⇒ Object

Process counter operations (create, update, or destroy) counter_id is the ID of the counter to operate on, or can be a `key` if operation is 'create'.

Parameters:

  • operation (String)

    The operation to perform ('create', 'update', or 'destroy')

  • counter_id (Integer/String)

    The ID of the counter to operate on (or `key` for 'create')

  • value (Integer, nil) (defaults to: nil)

    (optional) The new value for create/update operations. Ignored for destroy.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/workers/counter_operation_worker.rb', line 13

def perform(operation, counter_id, value = nil)
  case operation
  when 'update'
    update_counter(counter_id, value)
  when 'destroy'
    destroy_counter(counter_id)
  when 'create'
    create_counter(counter_id, value)
  else
    APMErrorHandler.report('Unknown counter operation', {
                             operation: operation,
                             counter_id: counter_id,
                           })
  end
end