2021-02-09 12:35:23 +01:00
|
|
|
class ChampFetchExternalDataJob < ApplicationJob
|
2024-04-05 10:42:44 +02:00
|
|
|
discard_on ActiveJob::DeserializationError
|
|
|
|
|
2023-05-30 11:43:56 +02:00
|
|
|
include Dry::Monads[:result]
|
|
|
|
|
2021-03-11 12:32:08 +01:00
|
|
|
def perform(champ, external_id)
|
2023-02-28 13:55:52 +01:00
|
|
|
return if champ.external_id != external_id
|
|
|
|
return if champ.data.present?
|
2021-02-09 12:35:23 +01:00
|
|
|
|
2023-05-30 11:43:56 +02:00
|
|
|
Sentry.set_tags(champ: champ.id)
|
|
|
|
Sentry.set_extras(external_id:)
|
|
|
|
|
|
|
|
result = champ.fetch_external_data
|
|
|
|
|
|
|
|
if result.is_a?(Dry::Monads::Result)
|
|
|
|
case result
|
|
|
|
in Success(data)
|
|
|
|
champ.update_with_external_data!(data:)
|
|
|
|
in Failure(retryable: true, reason:)
|
|
|
|
champ.log_fetch_external_data_exception(reason)
|
|
|
|
throw reason
|
|
|
|
in Failure(retryable: false, reason:)
|
|
|
|
champ.log_fetch_external_data_exception(reason)
|
|
|
|
Sentry.capture_exception(reason)
|
|
|
|
end
|
|
|
|
elsif result.present?
|
|
|
|
champ.update_with_external_data!(data: result)
|
|
|
|
end
|
2021-02-09 12:35:23 +01:00
|
|
|
end
|
|
|
|
end
|