Class: CrmNavbarFanoutWorker
- Inherits:
-
Object
- Object
- CrmNavbarFanoutWorker
- Includes:
- Sidekiq::Worker
- Defined in:
- app/workers/crm_navbar_fanout_worker.rb
Overview
Fans a single domain event (a new SmsMessage, a new voicemail CallRecord,
an inbound email Activity update, ...) out to every CRM user currently live
on the site, asking each one's badge to refresh.
Why fan out to "all live users" instead of "users actually affected by this
specific record"? Each badge count depends on the viewer's effective_watch_list_ids,
which is per-user state. Computing the precise affected set per event would
require duplicating the count query's filter logic here. Since the live user
set is small (engineers, sales reps, support — order of tens, not thousands)
and CrmNavbarBroadcaster short-circuits cheaply when a user's count hasn't
changed, broadcasting to all live users is both simpler and fast enough.
Coalescing happens one layer down in CrmNavbarRefreshWorker.schedule, so even
bursty events translate into bounded broadcast load.
Constant Summary collapse
- CHANNEL_BADGES =
Channels that historically had their own navbar dropdown (and therefore
their own badge), now merged into one Communications offcanvas. Inbound
writes from SmsMessage / CallRecord / Activity still call us with the
old channel name; we translate to the unified :communications badge so
the live counter still updates without those callers having to change. %w[sms voicemail email].freeze
Instance Method Summary collapse
Instance Method Details
#perform(badge) ⇒ Object
31 32 33 34 35 36 37 |
# File 'app/workers/crm_navbar_fanout_worker.rb', line 31 def perform(badge) badge = 'communications' if CHANNEL_BADGES.include?(badge.to_s) CrmNavbarLiveUsers.list.each do |user_id| CrmNavbarRefreshWorker.schedule(user_id: user_id, badge: badge) end end |