Module: Orders::DurableOrderExecution

Included in:
RebootWorker, ReloadWorker, UpgradeWorker
Defined in:
app/workers/orders/durable_order_execution.rb

Instance Method Summary collapse

Instance Method Details

#safely_execute_order(order_id, &block) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/workers/orders/durable_order_execution.rb', line 3

def safely_execute_order(order_id, &block)
  pid = Process.fork
  return unless pid.nil?

  Process.setsid

  begin
    Smartkiosk::Client::Logging.logger.debug "Started execution of order #{order_id}"
    yield
    Smartkiosk::Client::Logging.logger.debug "Completed execution of order #{order_id}"

  rescue => e
    Smartkiosk::Client::Logging.logger.debug "Execution of order #{order_id} failed: #{e}"

    begin
      AcknowledgeWorker.perform_async order_id, e.to_s
    rescue => ne
      Smartkiosk::Client::Logging.logger.debug "Unable to schedule AcknowlegeWorker #{ne}"
      sleep 1
      retry
    end
  end

  begin
    CompleteWorker.perform_async order_id
  rescue => ne
    Smartkiosk::Client::Logging.logger.debug "Unable to schedule CompleteWorker: #{ne}"
    sleep 1
    retry
  end

  begin
    ActiveRecord::Base.connection.reconnect!

    Order.find(order_id).update_attribute(:complete, true)
  rescue => ne
    Smartkiosk::Client::Logging.logger.debug "Unable to mark completion: #{ne}"
    sleep 1
    retry
  end

  Process.exit!
end