Class: PullPhoneQueueStatusWorker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Job
Defined in:
app/workers/pull_phone_queue_status_worker.rb

Overview

Sidekiq worker: pull phone queue status.

Also keeps the switchboard's queue roster warm (so its first render never
pays the per-queue PBX round trip) and audits orders changed OUTSIDE
Heatwave: the freshly pulled ring order is diffed against the previously
cached one, and a drift means someone edited the queue directly in
Switchvox — recorded as a PhoneQueueOrderChange with source
'external-switchvox' so the history page answers "who moved this?" even
when it wasn't anyone in the CRM.

Constant Summary collapse

PULL_QUEUE_IDS =

One pull feeds both consumers. Phone::Pbx::QUEUES (per-member logged-in
status) and PhoneQueue::REGISTRY (ring order) overlap on 11 queues, so
polling them separately asked the PBX for the same queue twice — 26
sequential getCurrentStatus calls per run, each capped by a 10s read
timeout, which is what filled AppSignal #6604 with timeouts.

(Phone::Pbx::QUEUES.values | PhoneQueue::REGISTRY.keys).freeze

Instance Method Summary collapse

Instance Method Details

#performObject

Runs the job.

Returns:

  • (Object)

    the result



27
28
29
30
31
32
33
34
35
36
# File 'app/workers/pull_phone_queue_status_worker.rb', line 27

def perform
  logger.info '[PullPhoneQueueStatusWorker] called'
  # Read the cached orders BEFORE the refresh below overwrites them.
  previous = PhoneQueue::REGISTRY.keys.index_with { |queue_id| Phone::QueueRoster.cached_member_order(queue_id) }
  observed_at = Time.current
  snapshot = Phone::Pbx.instance.get_queues_snapshot(PULL_QUEUE_IDS)
  EmployeePhoneStatus.pull_queue_status(Phone::Pbx.instance.queue_status_from_snapshot(snapshot), observed_at:)
  audit_external_reorders(previous, Phone::QueueRoster.refresh(snapshot))
  logger.info '[PullPhoneQueueStatusWorker] finished'
end