Sha256: 58727e15350ba4c54b1b83f777b9483a12cee268f4d24c47b3377c7e8d253e04

Contents?: true

Size: 1.35 KB

Versions: 3

Compression:

Stored size: 1.35 KB

Contents

module ThreeScaleToolbox
  module Commands
    module BackendCommand
      module CopyCommand
        class CopyMethodsTask
          include Task

          # entrypoint
          def run
            missing_methods.each(&method(:create_method))
            puts "created #{missing_methods.size} missing methods"
            invalidate_target_methods if missing_methods.size.positive?
          end

          private

          def create_method(method)
            # return silently if target metric hits does not exist
            return if target_hits.nil?

            Entities::BackendMethod.create(backend: target_backend,
                                           parent_id: target_hits.id,
                                           attrs:  method.attrs)
          rescue ThreeScaleToolbox::ThreeScaleApiError => e
            raise e unless ThreeScaleToolbox::Helper.system_name_already_taken_error?(e.apierrors)

            warn "[WARN] backend method #{method.attrs.fetch('system_name')} not created. " \
              'Backend metric with the same system_name exists.'
          end

          def missing_methods
            @missing_methods ||= ThreeScaleToolbox::Helper.array_difference(source_methods, target_methods) do |source, target|
              source.system_name == target.system_name
            end
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
3scale_toolbox-0.17.1 lib/3scale_toolbox/commands/backend_command/copy_command/copy_methods_task.rb
3scale_toolbox-0.17.0 lib/3scale_toolbox/commands/backend_command/copy_command/copy_methods_task.rb
3scale_toolbox-0.16.0 lib/3scale_toolbox/commands/backend_command/copy_command/copy_methods_task.rb