Class: Jumbotron::Workflows::ExecuteGameUpdatePolicyWorkflow

Inherits:
CommandTower::Workflows::ApplicationWorkflow
  • Object
show all
Defined in:
app/workflows/jumbotron/workflows/execute_game_update_policy_workflow.rb

Instance Method Summary collapse

Instance Method Details

#call(adapter_id:, policy_id:) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/workflows/jumbotron/workflows/execute_game_update_policy_workflow.rb', line 8

def call(adapter_id:, policy_id:)
  now = Time.current
  resolved = Services::Adapters::ResolveGameUpdatePolicy.call(
    adapter_id: adapter_id,
    policy_id: policy_id
  )
  return map_resolution_failure(resolved) unless resolved.success?

  adapter = resolved.data[:adapter]
  policy = resolved.data[:policy]
  selected = Services::Adapters::SelectEligibleGames.call(
    adapter: adapter,
    policy: policy,
    now: now
  )
  return map_selection_failure(selected) unless selected.success?

  league = selected.data[:league]
  games = selected.data[:games]
  built = Services::Adapters::BuildAcquisitionScopes.call(adapter: adapter, games: games)
  return map_selection_failure(built) unless built.success?

  scopes = built.data[:scopes]
  counts = blank_counts.merge(
    eligible_games: games.size,
    unique_scopes: scopes.size,
    skipped_incomplete_scope: built.data[:skipped_incomplete_scope]
  )

  return success_payload(adapter, policy, counts) if scopes.empty?

  run_scopes(adapter, league, scopes, counts)
  finish(adapter, policy, counts)
end