Class: Trinidad::Extensions::ThreadedResque::LifecycleListener

Inherits:
Object
  • Object
show all
Includes:
Tomcat::LifecycleListener
Defined in:
lib/trinidad_threaded_resque_extension/lifecycle_listener.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ LifecycleListener

Returns a new instance of LifecycleListener.



10
11
12
# File 'lib/trinidad_threaded_resque_extension/lifecycle_listener.rb', line 10

def initialize(options = {})
  @options = options
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'lib/trinidad_threaded_resque_extension/lifecycle_listener.rb', line 8

def options
  @options
end

#threadsObject

Returns the value of attribute threads.



8
9
10
# File 'lib/trinidad_threaded_resque_extension/lifecycle_listener.rb', line 8

def threads
  @threads
end

#workersObject

Returns the value of attribute workers.



8
9
10
# File 'lib/trinidad_threaded_resque_extension/lifecycle_listener.rb', line 8

def workers
  @workers
end

Instance Method Details

#lifecycleEvent(event) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/trinidad_threaded_resque_extension/lifecycle_listener.rb', line 14

def lifecycleEvent(event)
  case event.type
  when Trinidad::Tomcat::Lifecycle::AFTER_START_EVENT
    start_workers
  when Trinidad::Tomcat::Lifecycle::BEFORE_STOP_EVENT
    stop_workers
  end
end

#start_workersObject



23
24
25
26
27
# File 'lib/trinidad_threaded_resque_extension/lifecycle_listener.rb', line 23

def start_workers
  pre_require
  @workers = create_workers
  @threads = create_threads
end

#stop_workersObject



29
30
31
32
# File 'lib/trinidad_threaded_resque_extension/lifecycle_listener.rb', line 29

def stop_workers
  @workers.each { |w| w.shutdown } if @workers
  @threads.each { |t| t.join } if @threads
end