Sha256: 3fa82e70f172d01cb674dc0000b10276d327cec571fccc69efbe3eb2cb0be724
Contents?: true
Size: 1.3 KB
Versions: 10
Compression:
Stored size: 1.3 KB
Contents
module ThreeScaleToolbox module Commands module ServiceCommand module CopyCommand class CopyMetricsTask include Task def call logger.info "original service has #{source.metrics.size} metrics" logger.info "target service has #{target.metrics.size} metrics" missing_metrics.each(&method(:create_metric)) logger.info "created #{missing_metrics.size} metrics on the target service" report['missing_metrics_created'] = missing_metrics.size end private def create_metric(metric) new_metric = metric.attrs.reject { |key, _| %w[id links].include? key } Entities::Metric.create(service: target, attrs: new_metric) rescue ThreeScaleToolbox::ThreeScaleApiError => e raise e unless ThreeScaleToolbox::Helper.system_name_already_taken_error?(e.apierrors) warn "[WARN] metric #{metric.system_name} not created. " \ 'Method with the same system_name exists.' end def missing_metrics @missing_metrics ||= ThreeScaleToolbox::Helper.array_difference(source.metrics, target.metrics) do |s_m, t_m| s_m.system_name == t_m.system_name end end end end end end end
Version data entries
10 entries across 10 versions & 1 rubygems