Class: ProcessManager
- Inherits:
-
Object
- Object
- ProcessManager
- Includes:
- Singleton
- Defined in:
- lib/sinatra/extensions/processmanager.rb
Instance Attribute Summary collapse
-
#handlers ⇒ Object
readonly
Returns the value of attribute handlers.
Instance Method Summary collapse
- #clean(clazz) ⇒ Object
- #find(clazz) ⇒ Object
- #finish(handler) ⇒ Object
-
#initialize ⇒ ProcessManager
constructor
A new instance of ProcessManager.
- #run(*args) ⇒ Object
- #running?(clazz) ⇒ Boolean
Constructor Details
#initialize ⇒ ProcessManager
Returns a new instance of ProcessManager.
73 74 75 |
# File 'lib/sinatra/extensions/processmanager.rb', line 73 def initialize @handlers = [] end |
Instance Attribute Details
#handlers ⇒ Object (readonly)
Returns the value of attribute handlers.
71 72 73 |
# File 'lib/sinatra/extensions/processmanager.rb', line 71 def handlers @handlers end |
Instance Method Details
#clean(clazz) ⇒ Object
99 100 101 102 103 104 |
# File 'lib/sinatra/extensions/processmanager.rb', line 99 def clean(clazz) @handlers.select { |handler| handler.clazz == clazz }.each do |handler| handler.interrupt self.finish(handler) end end |
#find(clazz) ⇒ Object
77 78 79 |
# File 'lib/sinatra/extensions/processmanager.rb', line 77 def find(clazz) @handlers.find { |handler| handler.clazz == clazz } end |
#finish(handler) ⇒ Object
95 96 97 |
# File 'lib/sinatra/extensions/processmanager.rb', line 95 def finish(handler) @handlers -= [handler] end |
#run(*args) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/sinatra/extensions/processmanager.rb', line 81 def run(*args) clean(args.first.to_s) if !running?(args.first.to_s) handler = ProcessHandler.new(rand(1..100000000), args.first.name, args.first.to_s) clazz = args.first args[0] = handler clazz.perform_async(*args) @handlers << handler handler else find(args.first.to_s) end end |
#running?(clazz) ⇒ Boolean
106 107 108 |
# File 'lib/sinatra/extensions/processmanager.rb', line 106 def running?(clazz) !@handlers.select { |handler| handler.clazz == clazz }.empty? end |