Module: Faktory::Util

Includes:
ExceptionHandler
Included in:
CLI, Launcher, Manager, Processor
Defined in:
lib/faktory/util.rb

Overview

This module is part of Faktory core and not intended for extensions.

Constant Summary collapse

EXPIRY =
60 * 60 * 24

Instance Method Summary collapse

Methods included from ExceptionHandler

#handle_exception

Instance Method Details

#fire_event(event, reverse = false) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/faktory/util.rb', line 50

def fire_event(event, reverse = false)
  arr = Faktory.options[:lifecycle_events][event]
  arr.reverse! if reverse
  arr.each do |block|
    block.call
  rescue => ex
    handle_exception(ex, {context: "Exception during Faktory lifecycle event.", event: event})
  end
  arr.clear
end

#hostnameObject



38
39
40
# File 'lib/faktory/util.rb', line 38

def hostname
  ENV["DYNO"] || Socket.gethostname
end

#identityObject



46
47
48
# File 'lib/faktory/util.rb', line 46

def identity
  @@identity ||= "#{hostname}:#{$$}:#{process_nonce}"
end

#loggerObject



30
31
32
# File 'lib/faktory/util.rb', line 30

def logger
  Faktory.logger
end

#process_nonceObject



42
43
44
# File 'lib/faktory/util.rb', line 42

def process_nonce
  @@process_nonce ||= SecureRandom.hex(6)
end

#safe_thread(name, &block) ⇒ Object



23
24
25
26
27
28
# File 'lib/faktory/util.rb', line 23

def safe_thread(name, &block)
  Thread.new do
    Thread.current["faktory_label"] = name
    watchdog(name, &block)
  end
end

#server(&block) ⇒ Object



34
35
36
# File 'lib/faktory/util.rb', line 34

def server(&block)
  Faktory.server(&block)
end

#watchdog(last_words) ⇒ Object



16
17
18
19
20
21
# File 'lib/faktory/util.rb', line 16

def watchdog(last_words)
  yield
rescue Exception => ex # rubocop:disable Lint/RescueException
  handle_exception(ex, {context: last_words})
  raise ex
end