http_log.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. class Sequencer
  3. class Unit
  4. module Import
  5. module Common
  6. module Model
  7. class HttpLog < Sequencer::Unit::Base
  8. uses :dry_run, :action, :remote_id, :mapped, :exception
  9. def process
  10. return if dry_run
  11. ::HttpLog.create(
  12. direction: 'out',
  13. facility: facility,
  14. method: 'tcp',
  15. url: url,
  16. status: status,
  17. ip: nil,
  18. request: {
  19. content: mapped,
  20. },
  21. response: {
  22. message: response
  23. },
  24. created_by_id: 1,
  25. updated_by_id: 1,
  26. )
  27. end
  28. private
  29. def url
  30. "#{action} -> #{remote_id}"
  31. end
  32. def status
  33. @status ||= begin
  34. action == :failed ? :failed : :success
  35. end
  36. end
  37. def response
  38. exception ? exception.message : status
  39. end
  40. def facility
  41. raise "Missing implementation of '#{__method__}' method for '#{self.class.name}'"
  42. end
  43. end
  44. end
  45. end
  46. end
  47. end
  48. end