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 =
Manager roles.
DailyFocus::ConversationSharing::SALES_LEADERSHIP_ROLES
Instance Method Summary collapse
Instance Method Details
#perform(employee_id, conversation_id = nil, covered_employee_ids = []) ⇒ Object
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 |
# File 'app/workers/daily_focus_analysis_rep_worker.rb', line 20 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 = if conversation_id AssistantConversation.find_by(id: conversation_id) else ensure_conversation_for(employee, covered_ids) end return unless conversation 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 |