Sha256: 8d57ce99dc59677b00ee2bc906f3f26b1f2a4fd16fe89b47916890353d1853f5
Contents?: true
Size: 1.03 KB
Versions: 3
Compression:
Stored size: 1.03 KB
Contents
# frozen_string_literal: true module WorkerGlass # This module provides additional timeout functionality for background processing engine # @example Example usage with Sidekiq - will fail with timeout error after 10 seconds # class Worker # include Sidekiq::Worker # prepend WorkerGlass::Timeout # # self.timeout = 10 # # def perform(*args) # SlowService.new.run(*args) # end # end module Timeout # Adds a timeout class attribute to prepended class # @param base [Class] base class to which we prepend this module def self.prepended(base) base.class_attribute :timeout end # Executes a business logic with additional timeouts # @param args Any arguments that we passed when scheduling a background job # @raise [WorkerGlass::Errors::TimeoutNotDefined] if we didn't define timeout def perform(*args) raise Errors::TimeoutNotDefined unless self.class.timeout ::Timeout.timeout(self.class.timeout, Errors::TimeoutError) { super } end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
worker-glass-0.2.5 | lib/worker_glass/timeout.rb |
worker-glass-0.2.4 | lib/worker_glass/timeout.rb |
worker-glass-0.2.3 | lib/worker_glass/timeout.rb |