module Eco::API::UseCases::GraphQL::Helpers::Location module Command::Optimizations DEFAULT_COMMANDS_PER_PAGE = 45 DEFAULT_FORCE_CONTINUE = false # Available options are: # - :per_request -> on each request # - :per_batch -> at the end of each batch / stage (on last page) # - :once -> only when the script starts to run def default_tree_tracking_mode :per_request end # Helper to identify the commands payload block # @note # 1. Gives flexibility on at what time the structure should be retrieved # 2. This increases performacne, as we don't retrieve the full tree on # each request unless necessary/specified # 3. `nil` falls the block back to the `ecoportal-api-graphql` gem, which # has a default block that retrieves the structure # @return [Proc, NilClass] the payload block def scope_commands_block(idx, total, track_tree_mode: default_tree_tracking_mode) case track_tree_mode when :per_request nil when :once commands_payload_without_structure_block when :per_batch return nil if idx == total commands_payload_without_structure_block end end # Prevents each request from timing out def commands_per_page if self.class.const_defined?(:COMMANDS_PER_PAGE) self.class::COMMANDS_PER_PAGE else DEFAULT_COMMANDS_PER_PAGE end end # Whether to stop or continue on command fail def force_continue? if self.class.const_defined?(:FORCE_CONTINUE) self.class::FORCE_CONTINUE else DEFAULT_FORCE_CONTINUE end end # Commands payload without querying Structure # @note this servces the purpose of optimizing/speeding up the requests. def commands_payload_without_structure_block proc { clientMutationId error { # rubocop:disable Style/BlockDelimiters message conflictingIds validationErrors { # rubocop:disable Style/BlockDelimiters error message } } results { # rubocop:disable Style/BlockDelimiters command { # rubocop:disable Style/BlockDelimiters id state __typename } ok error { # rubocop:disable Style/BlockDelimiters conflictingIds message validationErrors { # rubocop:disable Style/BlockDelimiters error message } } } } end end end