Class: TrinidadScheduler::WebAppListener
- Defined in:
- lib/trinidad_scheduler_extension/scheduler_listener.rb
Instance Method Summary collapse
-
#initialize(servlet_context, options) ⇒ WebAppListener
constructor
A new instance of WebAppListener.
- #is_started? ⇒ Boolean
- #lifecycle_event(event) ⇒ Object
- #needs_started? ⇒ Boolean
Constructor Details
#initialize(servlet_context, options) ⇒ WebAppListener
Returns a new instance of WebAppListener.
5 6 7 8 9 10 11 12 13 |
# File 'lib/trinidad_scheduler_extension/scheduler_listener.rb', line 5 def initialize(servlet_context, ) @servlet_context = servlet_context # $servlet_context is set by jruby-rack. # If the sheduler jobs are loaded before the web app has been loaded they fail to initialize because $servlet_context is nil. # We prevent this to happen here. $servlet_context ||= servlet_context @options = TrinidadScheduler.(@servlet_context, @options) end |
Instance Method Details
#is_started? ⇒ Boolean
19 20 21 |
# File 'lib/trinidad_scheduler_extension/scheduler_listener.rb', line 19 def is_started? TrinidadScheduler.scheduler_exists?(@servlet_context) && TrinidadScheduler[@servlet_context].is_started end |
#lifecycle_event(event) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/trinidad_scheduler_extension/scheduler_listener.rb', line 23 def lifecycle_event(event) case event.type when org.apache.catalina.Lifecycle::START_EVENT then if needs_started? TrinidadScheduler[@servlet_context].start TrinidadScheduler[@servlet_context].resume_all end TrinidadScheduler.set_servlet_started(@servlet_context) when org.apache.catalina.Lifecycle::STOP_EVENT then TrinidadScheduler[@servlet_context].shutdown if is_started? end end |
#needs_started? ⇒ Boolean
15 16 17 |
# File 'lib/trinidad_scheduler_extension/scheduler_listener.rb', line 15 def needs_started? TrinidadScheduler.scheduler_exists?(@servlet_context) && !TrinidadScheduler[@servlet_context].is_started end |