Sha256: edd23b76cdcc1d48cd67f14002bf1345ace2f5a12ac41e93d5c89d19f90fa4b4

Contents?: true

Size: 1.09 KB

Versions: 4

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

require "sidekiq"
require "sidekiq-unique-jobs"

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

      attr_accessor :model
      delegate :global_registry_entity, to: :model
      delegate :global_registry_relationship, to: :model

      def initialize(model = nil)
        self.model = model
      end

      def perform(model_class, id)
        klass = model_class.is_a?(String) ? model_class.constantize : model_class
        self.model = klass.find(id)
      end

      def self.perform_async(*args)
        # Set global sidekiq_options
        worker = set(GlobalRegistry::Bindings.sidekiq_options)
        if worker == self # sidekiq 4.x
          super(*args)
        else # sidekiq 5.x
          worker.perform_async(*args)
        end
      rescue Redis::BaseError => e
        case GlobalRegistry::Bindings.redis_error_action
        when :raise
          raise
        when :log
          ::Rollbar.error(e) if Module.const_defined? :Rollbar
        when :ignore
          nil
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
global-registry-bindings-0.7.2 lib/global_registry_bindings/worker.rb
global-registry-bindings-0.7.1 lib/global_registry_bindings/worker.rb
global-registry-bindings-0.7 lib/global_registry_bindings/worker.rb
global-registry-bindings-0.6.3 lib/global_registry_bindings/worker.rb