Class: Trinidad::Extensions::Resque::ResqueLifecycleListener
- Inherits:
-
Object
- Object
- Trinidad::Extensions::Resque::ResqueLifecycleListener
- Includes:
- Tomcat::LifecycleListener
- Defined in:
- lib/resque_lifecycle_listener.rb
Instance Method Summary collapse
- #configure_workers ⇒ Object
-
#initialize(options) ⇒ ResqueLifecycleListener
constructor
A new instance of ResqueLifecycleListener.
- #invoke_workers(task) ⇒ Object
- #lifecycle_event(event) ⇒ Object
- #load_tasks ⇒ Object
- #start_workers ⇒ Object
- #stop_workers ⇒ Object
Constructor Details
#initialize(options) ⇒ ResqueLifecycleListener
Returns a new instance of ResqueLifecycleListener.
12 13 14 |
# File 'lib/resque_lifecycle_listener.rb', line 12 def initialize() @options = end |
Instance Method Details
#configure_workers ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/resque_lifecycle_listener.rb', line 39 def configure_workers task = 'resque:work' if @options[:count] ENV['COUNT'] = @options[:count].to_s task = 'resque:workers' end ENV['QUEUES'] ||= @options[:queues] ::Resque.redis = @options[:redis_host] load @options[:setup] if @options[:setup] task end |
#invoke_workers(task) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/resque_lifecycle_listener.rb', line 55 def invoke_workers(task) t = Rake::Task[task] t.application.[:trace] = true t.invoke rescue Errno::ECONNREFUSED puts "WARN: Cannot connect with Redis. Please restart the server when Redis is up again." @redis_econnref = true end |
#lifecycle_event(event) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/resque_lifecycle_listener.rb', line 16 def lifecycle_event(event) case event.type when Trinidad::Tomcat::Lifecycle::BEFORE_START_EVENT start_workers when Trinidad::Tomcat::Lifecycle::BEFORE_STOP_EVENT stop_workers end end |
#load_tasks ⇒ Object
33 34 35 36 37 |
# File 'lib/resque_lifecycle_listener.rb', line 33 def load_tasks Dir.glob(File.join(@options[:path], '**', '*.rb')).each do |path| load path end end |
#start_workers ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/resque_lifecycle_listener.rb', line 25 def start_workers Thread.new do load_tasks task = configure_workers invoke_workers task end end |
#stop_workers ⇒ Object
64 65 66 67 |
# File 'lib/resque_lifecycle_listener.rb', line 64 def stop_workers return if @redis_econnref # double check redis is connected, otherwise return ::Resque.workers.each { |w| w.shutdown! } end |