Class: DailyFocusAnalysisRepWorker
- Inherits:
-
Object
- Object
- DailyFocusAnalysisRepWorker
- Includes:
- Sidekiq::Job, Workers::StatusBroadcastable
- Defined in:
- app/workers/daily_focus_analysis_rep_worker.rb
Overview
Generates a Daily Focus Analysis for a sales rep (and optional covered reps) via Sunny tools.
Uses Assistant::ChatService + sales_management tools (unified path — no pre-injected CRM dumps).
Enqueued by DailyFocusAnalysisWorker per RunPolicy target, or from CRM generate with optional args.
Constant Summary collapse
- MANAGER_ROLES =
Default (sales) manager roles for ownership of sales briefings.
DailyFocus::ConversationSharing::SALES_LEADERSHIP_ROLES
Instance Attribute Summary
Attributes included from Workers::StatusBroadcastable
Instance Method Summary collapse
- #perform(employee_id, conversation_id = nil, covered_employee_ids = [], initiator = 'system') ⇒ void
Methods included from Workers::StatusBroadcastable::Overrides
Instance Method Details
#perform(employee_id, conversation_id = nil, covered_employee_ids = [], initiator = 'system') ⇒ void
This method returns an undefined value.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/workers/daily_focus_analysis_rep_worker.rb', line 24 def perform(employee_id, conversation_id = nil, covered_employee_ids = [], initiator = 'system') total 3 if jid.present? at 1, 'Preparing Daily Focus...' if jid.present? employee = Employee.find_by(id: employee_id) return unless employee covered_ids = Array(covered_employee_ids).flatten.map(&:to_i).uniq - [employee.id] covered_employees = Employee.where(id: covered_ids).includes(:employee_record).to_a conversation = if conversation_id AssistantConversation.find_by(id: conversation_id) else ensure_conversation_for(employee, covered_ids) end return unless conversation at 2, "Generating Daily Focus for #{employee.full_name}..." if jid.present? run_analysis(conversation, employee, covered_employees, initiator) if jid.present? at 3, 'Daily Focus ready for review' store( redirect_to: Rails.application.routes.url_helpers.assistant_path(conversation), info_message: "Daily Focus is ready for #{employee.full_name}." ) end Rails.logger.info("[DailyFocusAnalysisRepWorker] Generated daily focus for #{employee.full_name} " \ "(conversation #{conversation.id}, pending review)") rescue StandardError => e store(error_message: 'Daily Focus generation failed. Please try again.') if jid.present? Rails.logger.error("[DailyFocusAnalysisRepWorker] Failed for employee #{employee_id}: #{e.}\n#{e.backtrace.first(5).join("\n")}") ErrorReporting.error(e, source: :background, context: { employee_id: employee_id, conversation_id: conversation_id, worker: 'DailyFocusAnalysisRepWorker' }) end |