Skip to content

Commit

Permalink
Do not retry Fs::DownloadSentMessageRelatedMessagesJob if NoRelatedMe…
Browse files Browse the repository at this point in the history
…ssagesError
  • Loading branch information
luciajanikova committed Dec 3, 2024
1 parent ae918a4 commit 9fa0780
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 NoRelatedMessagesError < StandardError
end

retry_on NoRelatedMessagesError, 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 NoRelatedMessagesError 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::NoRelatedMessagesError) do
Fs::DownloadSentMessageRelatedMessagesJob.new.perform(outbox_message)
end
end
Expand Down

0 comments on commit 9fa0780

Please sign in to comment.