Class: Jumbotron::Services::Adapters::ExecuteLineAcquisitionScope

Inherits:
CommandTower::Services::ApplicationService
  • Object
show all
Defined in:
app/services/jumbotron/services/adapters/execute_line_acquisition_scope.rb

Instance Method Summary collapse

Instance Method Details

#callObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/services/jumbotron/services/adapters/execute_line_acquisition_scope.rb', line 10

def call
  if adapter.provider_cooling_down?
    context.outcome = :cooldown_active
    return
  end

  lease = Synchronization::Lease.new
  lease_scope = Synchronization::Lease.scope(
    adapter_id: adapter.adapter_id,
    endpoint: :competition_odds,
    acquisition: acquisition
  )
  held = lease.acquire(lease_scope)
  unless held.acquired?
    context.outcome = :contention
    return
  end

  begin
    execute_held
  ensure
    lease.release(lease_scope, token: held.token)
  end
end