Class: Toro::Processor
Instance Attribute Summary collapse
-
#proxy_id ⇒ Object
Returns the value of attribute proxy_id.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(manager) ⇒ Processor
constructor
A new instance of Processor.
- #process(job) ⇒ Object
Methods included from Actor
Constructor Details
#initialize(manager) ⇒ Processor
Returns a new instance of Processor.
18 19 20 |
# File 'lib/toro/processor.rb', line 18 def initialize(manager) @manager = manager end |
Instance Attribute Details
#proxy_id ⇒ Object
Returns the value of attribute proxy_id.
5 6 7 |
# File 'lib/toro/processor.rb', line 5 def proxy_id @proxy_id end |
Class Method Details
.default_middleware ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/toro/processor.rb', line 8 def default_middleware Middleware::Chain.new do |middleware| middleware.add Middleware::Server::Properties middleware.add Middleware::Server::Retry middleware.add Middleware::Server::ErrorStorage middleware.add Middleware::Server::Error end end |
Instance Method Details
#process(job) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/toro/processor.rb', line 22 def process(job) @manager.set_thread(proxy_id, Thread.current) Toro.logger.info "Processing #{job}" worker = job.class_name.constantize Toro::Database.with_connection do begin Toro.server_middleware.invoke(job, worker) do worker.new.perform(*job.args) end rescue Exception => exception Toro.logger.error "#{exception.class}: #{exception.}" Toro.logger.error exception.backtrace.join("\n") else Toro.logger.info "Processed #{job}" job.update_attributes( status: 'complete', finished_at: Time.now ) end end @manager.processor_complete(current_actor) if @manager.alive? end |