Class: Trinidad::Extensions::ResqueServerExtension
- Inherits:
-
ServerExtension
- Object
- ServerExtension
- Trinidad::Extensions::ResqueServerExtension
- Defined in:
- lib/trinidad_resque_extension.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #add_resque_listener(tomcat) ⇒ Object
- #configure(tomcat) ⇒ Object
- #init_resque_web(tomcat) ⇒ Object
-
#initialize(options) ⇒ ResqueServerExtension
constructor
A new instance of ResqueServerExtension.
- #prepare_options ⇒ Object
- #trap_signals(tomcat) ⇒ Object
Constructor Details
#initialize(options) ⇒ ResqueServerExtension
Returns a new instance of ResqueServerExtension.
19 20 21 22 23 24 |
# File 'lib/trinidad_resque_extension.rb', line 19 def initialize() super @options[:redis_host] ||= 'localhost:6379' @options[:queues] ||= 'trinidad_resque' @options[:path] ||= File.join('lib', 'tasks') end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
17 18 19 |
# File 'lib/trinidad_resque_extension.rb', line 17 def @options end |
Instance Method Details
#add_resque_listener(tomcat) ⇒ Object
34 35 36 |
# File 'lib/trinidad_resque_extension.rb', line 34 def add_resque_listener(tomcat) tomcat.host.add_lifecycle_listener(Trinidad::Extensions::Resque::ResqueLifecycleListener.new(@options)) end |
#configure(tomcat) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/trinidad_resque_extension.rb', line 26 def configure(tomcat) add_resque_listener(tomcat) init_resque_web(tomcat) unless @options[:disable_web] trap_signals(tomcat) end |
#init_resque_web(tomcat) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/trinidad_resque_extension.rb', line 38 def init_resque_web(tomcat) opts = app_context = tomcat.addWebapp(opts[:context_path], opts[:web_app_dir]) web_app = ResqueApp.new({}, opts) app_context.add_lifecycle_listener(Trinidad::Lifecycle::Default.new(web_app)) web_app end |
#prepare_options ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/trinidad_resque_extension.rb', line 49 def # where resque gem is resque_path = Gem::GemPathSearcher.new.find('resque').full_gem_path opts = { :context_path => '/resque', :jruby_min_runtimes => 1, :jruby_max_runtimes => 2, :libs_dir => 'libs', :classes_dir => 'classes', :public => 'public', :environment => 'production' } opts.deep_merge!(@options) opts[:web_app_dir] = File.('lib/resque/server', resque_path) opts end |
#trap_signals(tomcat) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/trinidad_resque_extension.rb', line 68 def trap_signals(tomcat) # trap signals and stop tomcat properly to make sure resque is also stopped properly trap('INT') do ::Resque.workers.each { |w| w.shutdown! } tomcat.stop end trap('TERM') do ::Resque.workers.each { |w| w.shutdown! } tomcat.stop end end |