Sha256: 1c8085681c4ff1260d4a2014533e3d4125f0f26f1c8ad2c6c18cada9e673ec58

Contents?: true

Size: 895 Bytes

Versions: 2

Compression:

Stored size: 895 Bytes

Contents

# frozen_string_literal: true

module WorkerGlass
  # This module provides a reentrancy functionality for background processing engine
  # @note If will reraise a given error - it does not silence them
  # @example Example usage with Sidekiq - if something fails, after_failure will be executed
  #   class Worker
  #     include Sidekiq::Worker
  #     prepend WorkerGlass::Reentrancy
  #
  #     def perform(*args)
  #       FailingService.new.run(*args)
  #     end
  #
  #     def after_failure(*args)
  #       FailingService.new.reset(*args)
  #     end
  #   end
  module Reentrancy
    # Executes a business logic with additional timeouts
    # @param args Any arguments that we passed when scheduling a background job
    def perform(*args)
      super
    rescue => exception
      WorkerGlass.logger.fatal(exception)
      after_failure(*args)
      raise exception
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
worker-glass-0.2.4 lib/worker_glass/reentrancy.rb
worker-glass-0.2.3 lib/worker_glass/reentrancy.rb