Module: Sequent::Util

Defined in:
lib/sequent/util/timer.rb,
lib/sequent/util/dry_run.rb,
lib/sequent/util/printer.rb,
lib/sequent/util/web/clear_cache.rb,
lib/sequent/util/skip_if_already_processing.rb

Defined Under Namespace

Modules: DryRun, Printer, Timer, Web

Class Method Summary collapse

Class Method Details

.done_processing(processing_key) ⇒ Object

Reset the given processing_key for the current Thread.

Usefull to make a block protected by skip_if_already_processing reentrant.



27
28
29
# File 'lib/sequent/util/skip_if_already_processing.rb', line 27

def self.done_processing(processing_key)
  Thread.current[processing_key] = nil
end

.skip_if_already_processing(processing_key) ⇒ Object

Returns if the current Thread is already processing work given the processing_key otherwise it yields the given &block.

Useful in a Queue and Processing strategy



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/sequent/util/skip_if_already_processing.rb', line 11

def self.skip_if_already_processing(processing_key)
  return if Thread.current[processing_key]

  begin
    Thread.current[processing_key] = true

    yield
  ensure
    Thread.current[processing_key] = nil
  end
end