Sha256: 31f4df777b778de2c0f91ea24658af1adad5ea11340368a4d6896da0f383fb9d

Contents?: true

Size: 956 Bytes

Versions: 4

Compression:

Stored size: 956 Bytes

Contents

# frozen_string_literal: true

require 'sidekiq'
require 'sidekiq-unique-jobs'

module GlobalRegistry #:nodoc:
  module Bindings #:nodoc:
    module Workers #:nodoc:
      class PullMdmIdWorker
        include Sidekiq::Worker

        def perform(model_class, id)
          model_class.find(id).send(:pull_mdm_id_from_global_registry)
        rescue ActiveRecord::RecordNotFound
          # If the record was deleted after the job was created, swallow it
          return
        rescue RestClient::ResourceNotFound
          Rails.logger.info "GR entity for #{self.class.name} #{id} does not exist; will _not_ retry"
        end
      end

      def self.mdm_worker_class(model_class)
        klass = Class.new(PullMdmIdWorker) do
          sidekiq_options unique: :until_timeout, unique_expiration: model_class.global_registry.mdm_timeout
        end
        const_set model_class.global_registry.mdm_worker_class_name, klass
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
global-registry-bindings-0.0.4 lib/global_registry_bindings/workers/pull_mdm_id_worker.rb
global-registry-bindings-0.0.3 lib/global_registry_bindings/workers/pull_mdm_id_worker.rb
global-registry-bindings-0.0.2 lib/global_registry_bindings/workers/pull_mdm_id_worker.rb
global-registry-bindings-0.0.1 lib/global_registry_bindings/workers/pull_mdm_id_worker.rb