Class: Trinidad::Extensions::Sidekiq::LifecycleListener

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = { }) ⇒ LifecycleListener

Returns a new instance of LifecycleListener.



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

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

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



6
7
8
# File 'lib/trinidad_sidekiq_extension/lifecycle_listener.rb', line 6

def options
  @options
end

#threadsObject

Returns the value of attribute threads.



6
7
8
# File 'lib/trinidad_sidekiq_extension/lifecycle_listener.rb', line 6

def threads
  @threads
end

#workersObject

Returns the value of attribute workers.



6
7
8
# File 'lib/trinidad_sidekiq_extension/lifecycle_listener.rb', line 6

def workers
  @workers
end

Instance Method Details

#lifecycleEvent(event) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/trinidad_sidekiq_extension/lifecycle_listener.rb', line 12

def lifecycleEvent(event)
  case event.type
    when Trinidad::Tomcat::Lifecycle::AFTER_START_EVENT
      STDOUT << "[Trinidad:Sidekiq] event [#{event.type}] << start >>\n" if options[:verbose]
      start_cli
    when Trinidad::Tomcat::Lifecycle::BEFORE_STOP_EVENT
      STDOUT << "[Trinidad:Sidekiq] event [#{event.type}] << stop >>\n" if options[:verbose]
      stop_cli
    else
      STDOUT << "[Trinidad:Sidekiq] event [#{event.type}] skipped\n" if options[:verbose]
  end
end

#start_cliObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/trinidad_sidekiq_extension/lifecycle_listener.rb', line 25

def start_cli
  STDOUT << "[Trinidad:Sidekiq] starting sidekiq bm with options [#{@options}]\n" if options[:verbose]
  unless options[:require]
    raise "You probably want to send a require option to the sidekiq background manager ..." if options[:verbose]
  end

  STDOUT << "[Trinidad:Sidekiq] getting it going ...\n"
  bm = ::Sidekiq::BackgroundManager.instance
  STDOUT << "[Trinidad:Sidekiq] got original bm (#{bm.class.name}) #{bm.inspect} ...\n" if options[:verbose]
  bm.configure @options
  STDOUT << "[Trinidad:Sidekiq] got modified bm (#{bm.class.name}) #{bm.inspect} ...\n" if options[:verbose]
  res = bm.run
  STDOUT << "[Trinidad:Sidekiq] got bm running (#{res.class.name}) #{res.inspect} ...\n" if options[:verbose]
end

#stop_cliObject



40
41
42
43
44
# File 'lib/trinidad_sidekiq_extension/lifecycle_listener.rb', line 40

def stop_cli
  STDOUT << "[Trinidad:Sidekiq] Stopping sidekiq cli ...\n" if options[:verbose]
  res = ::Sidekiq::BackgroundManager.instance.interrupt
  STDOUT << "[Trinidad:Sidekiq] got bm stopped (#{res.class.name})#{res.inspect} ...\n" if options[:verbose]
end