Class: OpportunityBriefing::Request

Inherits:
Object
  • Object
show all
Includes:
Service
Defined in:
app/services/opportunity_briefing/request.rb

Overview

Finds or creates the canonical Sunny thread for an opportunity and, only
when explicitly requested, enqueues a new CRM-grounded briefing turn.

Defined Under Namespace

Classes: Result

Constant Summary collapse

MODEL =
OpportunityBriefing::Generate::MODEL
PENDING_TTL =
15.minutes

Instance Method Summary collapse

Methods included from Service

#attributes_used, #build_result, call, #logger

Methods included from Service::Initializer

#initialize

Instance Method Details

#callObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/services/opportunity_briefing/request.rb', line 21

def call
  validate!

  lock_result = AssistantConversation.with_advisory_lock_result(lock_key, timeout_seconds: 0) do
    request_under_lock
  end
  return lock_result.result if lock_result&.lock_was_acquired?

  Result.new(
    conversation: canonical_conversation,
    status: :processing,
    error_message: 'This opportunity briefing is already being prepared.'
  )
end