Module: Eco::API::UseCases::GraphQL::Helpers::Location::Command

Includes:
Base, EndPoints, Language::AuxiliarLogger
Included in:
Samples::Location::Command::DSL
Defined in:
lib/eco/api/usecases/graphql/helpers/location/command.rb,
lib/eco/api/usecases/graphql/helpers/location/command/result.rb,
lib/eco/api/usecases/graphql/helpers/location/command/results.rb,
lib/eco/api/usecases/graphql/helpers/location/command/input_unit_response.rb

Defined Under Namespace

Modules: EndPoints Classes: Diff, Diffs, InputUnitResponse, Result, Results

Constant Summary

Constants included from EndPoints::Optimizations

EndPoints::Optimizations::DEFAULT_COMMANDS_PER_PAGE

Constants included from Base::TreeTracking

Base::TreeTracking::TAGTREE_BACKUP

Instance Attribute Summary

Attributes included from Lib::ErrorHandling

#exception, #exiting

Attributes included from Language::AuxiliarLogger

#logger

Attributes included from Base::TreeTracking

#current_tree, #previous_tree

Instance Method Summary collapse

Methods included from EndPoints

#add_commands, #create_draft, #delete_draft, #fetch_draft, #publish_draft

Methods included from EndPoints::Optimizations

#commands_payload_without_structure_block, #commands_per_page, #create_payload_without_structure_block, #force_continue?, #publish_payload_without_structure_block

Methods included from Base

#live_tree, #session_live_tree, #tagtree_id, #target_structure_id, #target_structure_id_const

Methods included from Language::AuxiliarLogger

#log

Methods included from Base::TreeTracking

#backup_tree, #track_current_tree, #track_current_tree?

Instance Method Details

#sliced_batches(batch_input, size: commands_per_page, desc: :input) ⇒ Object

Note:

it does the API call.

Returns see #with_sliced_input.

Returns:

  • see #with_sliced_input



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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/eco/api/usecases/graphql/helpers/location/command.rb', line 11

def sliced_batches(
  batch_input,
  size: commands_per_page,
  desc: :input
)
  dry_run_msg = simulate? ? '(dry-run) ' : ''

  if batch_input[:commands].empty?
    msg  = "#{dry_run_msg}No commands for '#{desc}'."
    msg << ' Skipping batch...' unless simulate?
    log(:info) { msg }

    return
  end

  done = 0
  with_sliced_input(batch_input, size: size) do |sliced_input, page, pages, count, total|
    msg  = "#{dry_run_msg}Launching '#{desc}' request #{page} (of #{pages}) "
    msg << "with #{count} commands (done #{done} of #{total})..."
    log(:info) { msg }

    unless simulate? && !options.dig(:requests, :backup)
      watermark = "tree_update_#{desc}_response_#{page}_of_#{pages}"

      backup(sliced_input, type: watermark)
    end

    if simulate? && page < 3
      log(:info) {
        JSON.pretty_generate(sliced_input)
      }
    end

    # fetch structure? (by using default, when curr_block == nil)
    # We should only fetch at the very end (last standard stage)
    #   - We will explicitly fetch the draft structure before re-archive.
    response = add_commands(
      sliced_input,
      &commands_payload_without_structure_block
    )

    watermark = "tree_update_#{desc}_response_#{page}_of_#{pages}"
    backup(response, type: watermark) unless simulate?

    done += count
    yield(sliced_input, response, page, pages, done, total) if block_given?
  end
end

#with_sliced_input(input_data, size: commands_per_page) ⇒ Array<Array>

Returns pairs of sliced_input and response thereof.

Parameters:

  • input_data (Hash)

    input for the endpoint mutation.ApplyCommandsToLocationStructure.

Returns:

  • (Array<Array>)

    pairs of sliced_input and response thereof.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/eco/api/usecases/graphql/helpers/location/command.rb', line 62

def with_sliced_input(input_data, size: commands_per_page)
  comms = input_data[:commands]
  total = comms.count
  pages = (total.to_f / size).ceil.to_i
  page  = 1
  out   = []

  comms.each_slice(size) do |comms_slice|
    sliced_input = input_data.slice(:clientMutationId, :id).merge(commands: comms_slice)

    yield(sliced_input, page, pages, comms_slice.count, total).tap do |response|
      out.push([sliced_input, response])
      page += 1
    end
  end

  out
end