Class: Archfiend::ThreadLoop

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
SharedLoop::Runnable
Defined in:
lib/archfiend/thread_loop.rb

Direct Known Subclasses

BarThreadLoop

Constant Summary collapse

EXCEPTION_DELAY =

Seconds to sleep for after rescuing recoverable exception

1

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Methods included from SharedLoop::Runnable

#log_exception, #run

Class Attribute Details

.subclassesObject (readonly)

Returns the value of attribute subclasses.



13
14
15
# File 'lib/archfiend/thread_loop.rb', line 13

def subclasses
  @subclasses
end

Instance Attribute Details

#appObject

Returns the value of attribute app.



10
11
12
# File 'lib/archfiend/thread_loop.rb', line 10

def app
  @app
end

Class Method Details

.inherited(child_class) ⇒ Object

Collects all subclasses in the class instance variable



16
17
18
19
# File 'lib/archfiend/thread_loop.rb', line 16

def inherited(child_class)
  @subclasses ||= []
  @subclasses.push(child_class)
end

.start_all(app) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/archfiend/thread_loop.rb', line 21

def start_all(app)
  (subclasses || []).map do |thread_loop_class|
    th = Thread.new do
      instance = thread_loop_class.new
      instance.app = app
      app.logger.info "Starting thread #{thread_loop_class}"
      instance.run
    end
    th[:name] = thread_loop_class.name
    th
  end
end