class ProcessManager
Attributes
handlers[R]
Public Class Methods
new()
click to toggle source
# File lib/sinatra/extensions/processmanager.rb, line 75 def initialize @handlers = [] end
Public Instance Methods
clean(clazz,user_id)
click to toggle source
# File lib/sinatra/extensions/processmanager.rb, line 102 def clean(clazz,user_id) @handlers.select { |handler| handler.clazz == clazz && handler.user_id == user_id }.each do |handler| handler.interrupt self.finish(handler) end end
find(clazz,user_id)
click to toggle source
# File lib/sinatra/extensions/processmanager.rb, line 79 def find(clazz,user_id) @handlers.find { |handler| handler.clazz == clazz && handler.user_id == user_id } end
finish(handler)
click to toggle source
# File lib/sinatra/extensions/processmanager.rb, line 98 def finish(handler) @handlers -= [handler] end
run(*args)
click to toggle source
# File lib/sinatra/extensions/processmanager.rb, line 83 def run(*args) user_id = args[1][:user_id] clean(args.first.to_s,user_id) if !running?(args.first.to_s,user_id) handler = ProcessHandler.new(rand(1..100000000), args.first.name, args.first.to_s, user_id) clazz = args.first args[0] = handler clazz.perform_async(*args) @handlers << handler handler else find(args.first.to_s,user_id) end end
running?(clazz,user_id)
click to toggle source
# File lib/sinatra/extensions/processmanager.rb, line 109 def running?(clazz,user_id) !@handlers.select { |handler| handler.clazz == clazz && handler.user_id == user_id }.empty? end