Sha256: 76b08bd8cc740f6ec2e3ba4220b10a2bc9fe6ca5bde56614a357bb94c66adfa6
Contents?: true
Size: 1022 Bytes
Versions: 1
Compression:
Stored size: 1022 Bytes
Contents
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) fail Errors::TimeoutNotDefined unless self.class.timeout ::Timeout.timeout(self.class.timeout, Errors::TimeoutError) { super } end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
worker-glass-0.2.1 | lib/worker_glass/timeout.rb |