Class: CrmNavbarPeriodicRefreshWorker
- Inherits:
-
Object
- Object
- CrmNavbarPeriodicRefreshWorker
- Includes:
- Sidekiq::Job
- Defined in:
- app/workers/crm_navbar_periodic_refresh_worker.rb
Overview
5-minute server-side backstop for live CRM navbar badge updates.
Runs from sidekiq-scheduler (see config/sidekiq_*_schedule.yml). For
every user currently in CrmNavbarLiveUsers, schedules a refresh of
the communications and pinned badges via CrmNavbarRefreshWorker,
which coalesces with a 2-second NX lock so this naturally deduplicates
against any event-driven broadcast that just fired.
Badge updates are normally pushed in real time by CrmNavbarBroadcaster
on the relevant after_commit callbacks (sms / voicemail / email /
search). The push path can lose a broadcast if the user's WebSocket
happens to be disconnected at the moment of the broadcast (laptop
sleeping, network change mid-publish, etc.). ActionCable's consumer
reconnects automatically with exponential backoff and
turbo_stream_from resubscribes — but there is no replay of the
broadcasts that were missed during the gap. This worker re-pushes the
current truth every 5 min so the gap is bounded.
Phone presence (presence_dot) is intentionally excluded:
- It changes far less often than counts (the rep's phone state, not
incoming messages). - It is already kept in sync by
EmployeePhoneStatus#after_commit
andSyncPhoneStatusWorkerwhich runs every 10 min during
business hours. Re-broadcasting it from here would just add load
without filling a real gap.
Instance Method Summary collapse
-
#perform ⇒ Object
:reek:UtilityFunction.
Instance Method Details
#perform ⇒ Object
:reek:UtilityFunction
51 52 53 54 55 56 |
# File 'app/workers/crm_navbar_periodic_refresh_worker.rb', line 51 def perform CrmNavbarLiveUsers.list.each do |user_id| CrmNavbarRefreshWorker.schedule(user_id: user_id, badge: :communications) CrmNavbarRefreshWorker.schedule(user_id: user_id, badge: :pinned) end end |