class Actions::Middleware::KeepCurrentRequestID

Public Instance Methods

delay(*args) click to toggle source
# File lib/smart_proxy_dynflow/middleware/keep_current_request_id.rb, line 6
def delay(*args)
  pass(*args).tap { store_current_request_id }
end
finalize() click to toggle source
# File lib/smart_proxy_dynflow/middleware/keep_current_request_id.rb, line 20
def finalize
  restore_current_request_id { pass }
end
hook(*args) click to toggle source

Run all execution plan lifecycle hooks as the original request_id

# File lib/smart_proxy_dynflow/middleware/keep_current_request_id.rb, line 25
def hook(*args)
  restore_current_request_id { pass(*args) }
end
plan(*args) click to toggle source
# File lib/smart_proxy_dynflow/middleware/keep_current_request_id.rb, line 10
def plan(*args)
  with_current_request_id do
    pass(*args).tap { store_current_request_id }
  end
end
run(*args) click to toggle source
# File lib/smart_proxy_dynflow/middleware/keep_current_request_id.rb, line 16
def run(*args)
  restore_current_request_id { pass(*args) }
end

Private Instance Methods

restore_current_request_id() { || ... } click to toggle source
# File lib/smart_proxy_dynflow/middleware/keep_current_request_id.rb, line 43
def restore_current_request_id
  unless (restored_id = action.input[:current_request_id]).nil?
    old_id = ::Logging.mdc['request']
    if !old_id.nil? && old_id != restored_id
      action.action_logger.warn('Changing request id %{request_id} to saved id %{saved_id}' % { :saved_id => restored_id, :request_id => old_id })
    end
    ::Logging.mdc['request'] = restored_id
  end
  yield
ensure
  # Reset to original request id only when not nil
  # Otherwise, keep the id until it's cleaned in  Dynflow's run_user_code block
  # so that it will stay valid for the rest of the processing of the current step
  # (even outside of the middleware lifecycle)
  ::Logging.mdc['request'] = old_id unless old_id.nil?
end
store_current_request_id() click to toggle source
# File lib/smart_proxy_dynflow/middleware/keep_current_request_id.rb, line 39
def store_current_request_id
  action.input[:current_request_id] = ::Logging.mdc['request']
end
with_current_request_id() { || ... } click to toggle source
# File lib/smart_proxy_dynflow/middleware/keep_current_request_id.rb, line 31
def with_current_request_id(&block)
  if action.input[:current_request_id].nil?
    yield
  else
    restore_current_request_id(&block)
  end
end