Class: SidekiqGlass::Timeout

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq_glass/timeout.rb

Overview

Timeout class

Defined Under Namespace

Classes: TimeoutError

Class Method Summary collapse

Class Method Details

.perform(time, &block) ⇒ Object

Executed given method and raises exception if it takes to much time

Examples:

Execute a block of code for max 5 seconds

::System::Timeout.perform(5) do
  # code that should run max 5 seconds
end

Parameters:

  • time (Integer)

    in seconds that we allow given block to run

  • block (Block)

    of code that we want to execute with timeout

Returns:

  • Value returned by block

Raises:



17
18
19
# File 'lib/sidekiq_glass/timeout.rb', line 17

def self.perform(time, &block)
  ::Timeout.timeout(time, TimeoutError) { block.call }
end