Module: Eco::API::UseCases::GraphQL::Helpers::Location::Command
- Includes:
- Base, 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
Defined Under Namespace
Constant Summary collapse
- COMMANDS_PER_PAGE =
Prevents each request from timing out
45- FORCE_CONTINUE =
Whether to stop or continue on command fail
false
Constants included from Base
Instance Attribute Summary
Attributes included from Base
Attributes included from Base
Attributes included from Language::AuxiliarLogger
Instance Method Summary collapse
- #commands_per_page ⇒ Object
- #force_continue? ⇒ Boolean
-
#input(commands, force_continue: force_continue?) ) ⇒ Object
With given the commands, it generates the input of the endpoint mutation.
-
#sliced_batches(batch_input, size: commands_per_page, desc: :input, logging: true) ⇒ Object
See #with_sliced_input.
-
#with_sliced_input(input_data, size: commands_per_page) ⇒ Array<Array>
Pairs of
sliced_inputandresponsethereof.
Methods included from Base
#backup_tree, #live_tree, #tagtree_id, #target_structure_id, #track_current_tree
Methods included from Base
#backup, #config, #exit_error, #graphql, #simulate?
Methods included from Language::AuxiliarLogger
Instance Method Details
#commands_per_page ⇒ Object
11 12 13 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command.rb', line 11 def commands_per_page self.class::COMMANDS_PER_PAGE end |
#force_continue? ⇒ Boolean
15 16 17 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command.rb', line 15 def force_continue? self.class::FORCE_CONTINUE end |
#input(commands, force_continue: force_continue?) ) ⇒ Object
With given the commands, it generates the input of the endpoint mutation.
21 22 23 24 25 26 27 28 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command.rb', line 21 def input(commands, force_continue: force_continue?) { clientMutationId: "", id: target_structure_id, force: force_continue, commands: commands } end |
#sliced_batches(batch_input, size: commands_per_page, desc: :input, logging: true) ⇒ Object
Returns see #with_sliced_input.
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 59 60 61 62 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command.rb', line 31 def sliced_batches(batch_input, size: commands_per_page, desc: :input, logging: true) 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})..." logger.info { msg } response = nil unless simulate? && !.dig(:requests, :backup) backup(sliced_input, type: "tree_update_#{desc}_request_#{page}_of_#{pages}") end if simulate? log(:info) { sliced_input.pretty_inspect } if page < 3 else response = graphql.locationStructure.applyCommands(input: sliced_input) backup(response, type: "tree_update_#{desc}_response_#{page}_of_#{pages}") end 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.
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 66 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 |