Class: DailyFocusAnalysisRepWorker
- Inherits:
-
Object
- Object
- DailyFocusAnalysisRepWorker
- Includes:
- Sidekiq::Job
- 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 =
DailyFocus::ConversationSharing::SALES_LEADERSHIP_ROLES
Instance Method Summary collapse
Instance Method Details
#perform(employee_id, conversation_id = nil, covered_employee_ids = []) ⇒ Object
19 20 21 22 23 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 |
# File 'app/workers/daily_focus_analysis_rep_worker.rb', line 19 def perform(employee_id, conversation_id = nil, covered_employee_ids = []) 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 = conversation_id ? AssistantConversation.find_by(id: conversation_id) : nil if conversation.nil? return if already_generated_today?(employee) manager = Employee.by_role(MANAGER_ROLES).active_employees.first return unless manager conversation = create_conversation(employee, manager, covered_ids: covered_ids) end run_analysis(conversation, employee, covered_employees) Rails.logger.info("[DailyFocusAnalysisRepWorker] Generated daily focus for #{employee.full_name} " \ "(conversation #{conversation.id}, pending review)") rescue StandardError => e 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 |