Class: DailyFocusAnalysisWorker
- Inherits:
-
Object
- Object
- DailyFocusAnalysisWorker
- Includes:
- Sidekiq::Job
- Defined in:
- app/workers/daily_focus_analysis_worker.rb
Overview
Weekday orchestrator that fans out Daily Focus Analysis generation
to one DailyFocusAnalysisRepWorker per active sales + technical support
rep (via RunPolicy automation targets), then enqueues the manager digest
after a delay.
Runs early and schedules forward rather than generating on the spot, because
the two audiences want different timing:
- Sales keeps the long-standing 8:00 CT slot.
- Support is generated just before each rep's own shift. The tech backlog is a
morning artefact — tickets arrive overnight from users and from BPO — so a
fixed 8:00 briefing is already stale for a 7:30 start, and a rep starting at
8:30 wants the triage their manager did in the preceding hour reflected in
it. Asked for by Anatoliy, Basecamp 10137434670.
Constant Summary collapse
- MANAGER_REPORT_DELAY =
Manager report delay, measured from the last briefing enqueued.
20.minutes
- SUPPORT_LEAD =
Start a support rep's briefing this far ahead of their shift so it is
waiting when they sit down; generation takes several minutes. 10.minutes
- SALES_HOUR =
The hour sales briefings have always been generated at, CT.
8- STAGGER =
Spacing between jobs sharing a start time, so a burst does not land at once.
30.seconds
Instance Method Summary collapse
-
#perform ⇒ Object
Runs the job.
Instance Method Details
#perform ⇒ Object
Runs the job.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/workers/daily_focus_analysis_worker.rb', line 36 def perform # One reference time for the whole run. Taking Time.current per target gave # each clamped slot a microsecond-different value, so group_by saw them as # distinct keys, every group restarted its stagger at zero, and the jobs it # was meant to space out all landed at once — precisely on a late run, when # everything clamps to "now". now = Time.current sales = DailyFocus::RunPolicy.new(date: Date.current).automation_targets support = DailyFocus::RunPolicy.new(date: Date.current, audience: :support).automation_targets Rails.logger.info("[DailyFocusAnalysisWorker] Scheduling daily focus for #{sales.size + support.size} targets " \ "(#{sales.size} sales at #{SALES_HOUR}:00, #{support.size} support before their shifts)") last_run_at = [schedule_sales(sales, now), schedule_support(support, now)].compact.max || now DailyFocusManagerReportWorker.perform_at(last_run_at + MANAGER_REPORT_DELAY) Rails.logger.info("[DailyFocusAnalysisWorker] Scheduled; digest at #{last_run_at + MANAGER_REPORT_DELAY}") end |