Skip to content

Commit

Permalink
Merge pull request #518 from slovensko-digital/GO-164/do_not_retry_do…
Browse files Browse the repository at this point in the history
…wnload_job_if_no_messages

GO-164 Do not retry Fs::DownloadSentMessageRelatedMessagesJob if NoRelatedMessagesError
  • Loading branch information
luciajanikova authored Dec 3, 2024
2 parents ae918a4 + 7a6db06 commit 0839fd7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion app/jobs/fs/download_sent_message_related_messages_job.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
module Fs
class DownloadSentMessageRelatedMessagesJob < ApplicationJob
class MissingRelatedMessagesError < StandardError
end

retry_on MissingRelatedMessagesError, attempts: 1 do |_job, _error|
# no-op
end

def perform(outbox_message, from: nil, to: nil, fs_client: FsEnvironment.fs_client, batch_size: 25)
raise unless outbox_message.box.is_a?(Fs::Box)
return unless outbox_message.box.syncable?
Expand All @@ -9,7 +16,7 @@ def perform(outbox_message, from: nil, to: nil, fs_client: FsEnvironment.fs_clie
0.step do |k|
received_messages = fs_api.fetch_received_messages(sent_message_id: outbox_message.metadata['fs_message_id'], page: k + 1, count: batch_size, from: from, to: to)

raise "No related messages!" if outbox_message.thread.messages.excluding(outbox_message).none? && received_messages['messages'].none? && outbox_message.delivered_at < 1.hour.ago
raise MissingRelatedMessagesError if outbox_message.thread.messages.excluding(outbox_message).none? && received_messages['messages'].none? && outbox_message.delivered_at < 1.hour.ago

received_messages['messages'].each do |received_message|
::Fs::DownloadReceivedMessageJob.perform_later(received_message['message_id'], box: outbox_message.box)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Fs::DownloadSentMessageRelatedMessagesJobTest < ActiveJob::TestCase
**{sent_message_id: outbox_message.metadata['fs_message_id'], page: 1, count: 25, from: nil, to: nil}

FsEnvironment.fs_client.stub :api, fs_api do
assert_raise(StandardError, match: /No related messages!/) do
assert_raise(Fs::DownloadSentMessageRelatedMessagesJob::MissingRelatedMessagesError) do
Fs::DownloadSentMessageRelatedMessagesJob.new.perform(outbox_message)
end
end
Expand Down

0 comments on commit 0839fd7

Please sign in to comment.