Sha256: 9d285bf75da307d8b28d4e84772ae1fe335fbc9e77ad5bdbe900c3b6939dbc6c

Contents?: true

Size: 1.23 KB

Versions: 34

Compression:

Stored size: 1.23 KB

Contents

module Orders
  module DurableOrderExecution
    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
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
smartkiosk-client-0.2.1 app/workers/orders/durable_order_execution.rb
smartkiosk-client-0.2 app/workers/orders/durable_order_execution.rb
smartkiosk-client-0.1.19 app/workers/orders/durable_order_execution.rb
smartkiosk-client-0.1.18 app/workers/orders/durable_order_execution.rb
smartkiosk-client-0.1.17 app/workers/orders/durable_order_execution.rb
smartkiosk-client-0.1.16 app/workers/orders/durable_order_execution.rb
smartkiosk-client-0.1.15 app/workers/orders/durable_order_execution.rb
smartkiosk-client-0.1.14 app/workers/orders/durable_order_execution.rb
smartkiosk-client-0.1.13 app/workers/orders/durable_order_execution.rb
smartkiosk-client-0.1.12 app/workers/orders/durable_order_execution.rb
smartkiosk-client-0.1.11 app/workers/orders/durable_order_execution.rb
smartkiosk-client-0.1.10 app/workers/orders/durable_order_execution.rb
smartkiosk-client-0.1.9 app/workers/orders/durable_order_execution.rb
smartkiosk-client-0.1.8 app/workers/orders/durable_order_execution.rb
smartkiosk-client-0.1.7 app/workers/orders/durable_order_execution.rb
smartkiosk-client-0.1.6 app/workers/orders/durable_order_execution.rb
smartkiosk-client-0.1.5 app/workers/orders/durable_order_execution.rb
smartkiosk-client-0.1.4 app/workers/orders/durable_order_execution.rb
smartkiosk-client-0.1.3 app/workers/orders/durable_order_execution.rb
smartkiosk-client-0.1.2 app/workers/orders/durable_order_execution.rb