request.rb 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. class Sequencer::Unit::Import::Zendesk::Ticket::Comment::Attachment::Request < Sequencer::Unit::Base
  3. prepend ::Sequencer::Unit::Import::Common::Model::Mixin::Skip::Action
  4. skip_action :skipped
  5. uses :resource, :instance
  6. provides :response, :action
  7. def process
  8. if response.success?
  9. state.provide(:response, response)
  10. else
  11. skip_attachment
  12. end
  13. end
  14. private
  15. def response
  16. @response ||= fetch
  17. end
  18. def fetch
  19. attachment_response = nil
  20. 5.times do |iteration|
  21. attachment_response = UserAgent.get(
  22. resource.content_url,
  23. {},
  24. {
  25. open_timeout: 20,
  26. read_timeout: 240,
  27. verify_ssl: true,
  28. },
  29. )
  30. return attachment_response if attachment_response.success?
  31. logger.info "Sleeping 10 seconds after attachment request error and retry (##{iteration + 1}/5)."
  32. sleep 10
  33. end
  34. attachment_response
  35. end
  36. def skip_attachment
  37. logger.error "Skipping. Error while downloading Attachment from '#{resource.content_url}': #{response.error} (ticket_id: #{instance.ticket_id}, article_id: #{instance.id})"
  38. state.provide(:action, :skipped)
  39. end
  40. end