Class: Toro::Processor

Inherits:
Object
  • Object
show all
Includes:
Actor
Defined in:
lib/toro/processor.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Actor

included

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_idObject

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_middlewareObject


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.message}"
      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