Sha256: cf488675d04f975d6f6ee56c066b87709fb1eae6dd3c21f262c0baff978296ba

Contents?: true

Size: 1.49 KB

Versions: 21

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal: true

module NeetoCommonsBackend
  module BaseWorkers
    class Base
      include Sidekiq::Worker
      sidekiq_retries_exhausted do |message, exception|
        Sidekiq.logger.warn "Failed #{message['class']} with #{message['args']}: #{message['error_message']}"
        context = { class: message["class"], args: message["args"], error_message: message["error_message"] }
        Honeybadger.notify(exception, context:)
      end

      def self.perform_unique_async(*arguments)
        self.delete_matched(name, arguments)

        self.perform_async(arguments)
      end

      def self.perform_unique_in(t, *arguments)
        self.delete_matched(name, arguments)

        self.perform_in(t, arguments)
      end

      def self.perform_unique_at(t, *arguments)
        self.delete_matched(name, arguments)

        self.perform_at(t, arguments)
      end

      def self.delete_matched(worker_name, arguments)
        set = Sidekiq::ScheduledSet.new

        set = if arguments.is_a?(Array) && arguments.first.is_a?(String)
          set.scan arguments.first
              elsif arguments.is_a?(String)
                set.scan arguments
              else
                set.scan worker_name
        end

        set.each do |job|
          job.delete if job.display_class == worker_name && job.args == [arguments]
        end
      end

      def perform(*arguments)
        Honeybadger.context(job_name: self.class.name, app_name: Rails.application.engine_name)
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
neeto-commons-backend-1.0.109 app/workers/neeto_commons_backend/base_workers/base.rb
neeto-commons-backend-1.0.108 app/workers/neeto_commons_backend/base_workers/base.rb
neeto-commons-backend-1.0.107 app/workers/neeto_commons_backend/base_workers/base.rb
neeto-commons-backend-1.0.106 app/workers/neeto_commons_backend/base_workers/base.rb
neeto-commons-backend-1.0.105 app/workers/neeto_commons_backend/base_workers/base.rb
neeto-commons-backend-1.0.104 app/workers/neeto_commons_backend/base_workers/base.rb
neeto-commons-backend-1.0.103 app/workers/neeto_commons_backend/base_workers/base.rb
neeto-commons-backend-1.0.102 app/workers/neeto_commons_backend/base_workers/base.rb
neeto-commons-backend-1.0.101 app/workers/neeto_commons_backend/base_workers/base.rb
neeto-commons-backend-1.0.100 app/workers/neeto_commons_backend/base_workers/base.rb
neeto-commons-backend-1.0.99 app/workers/neeto_commons_backend/base_workers/base.rb
neeto-commons-backend-1.0.98 app/workers/neeto_commons_backend/base_workers/base.rb
neeto-commons-backend-1.0.97 app/workers/neeto_commons_backend/base_workers/base.rb
neeto-commons-backend-1.0.96 app/workers/neeto_commons_backend/base_workers/base.rb
neeto-commons-backend-1.0.95 app/workers/neeto_commons_backend/base_workers/base.rb
neeto-commons-backend-1.0.94 app/workers/neeto_commons_backend/base_workers/base.rb
neeto-commons-backend-1.0.93 app/workers/neeto_commons_backend/base_workers/base.rb
neeto-commons-backend-1.0.92 app/workers/neeto_commons_backend/base_workers/base.rb
neeto-commons-backend-1.0.91 app/workers/neeto_commons_backend/base_workers/base.rb
neeto-commons-backend-1.0.90 app/workers/neeto_commons_backend/base_workers/base.rb