fix(app-store): keep sync cursor on review failures

This commit is contained in:
Muhsin
2026-06-03 13:40:14 +04:00
parent 0cdcf30c39
commit 4e9abd6f08
3 changed files with 18 additions and 1 deletions
@@ -4,12 +4,16 @@ class Inboxes::FetchAppStoreReviewsJob < ApplicationJob
def perform(channel)
return unless channel.account.feature_enabled?(:channel_app_store)
failed = false
channel.fetch_reviews.each do |review_payload|
::AppStore::ReviewBuilder.new(review_payload: review_payload, channel: channel).perform
rescue StandardError => e
failed = true
ChatwootExceptionTracker.new(e, account: channel.account).capture_exception
end
return if failed
channel.update!(last_synced_at: Time.current)
rescue StandardError => e
ChatwootExceptionTracker.new(e, account: channel.account).capture_exception
@@ -15,5 +15,6 @@ class RepurposeMessageReplyToFlagForChannelAppStore < ActiveRecord::Migration[7.
config.value = config.value.reject { |feature| feature['name'] == 'message_reply_to' }
config.save!
GlobalConfig.clear_cache
end
end
@@ -38,7 +38,19 @@ RSpec.describe Inboxes::FetchAppStoreReviewsJob do
described_class.perform_now(channel)
expect(exception_tracker).to have_received(:capture_exception)
expect(channel.reload.last_synced_at).to be_present
end
it 'does not update the sync timestamp when a review fails to build' do
exception_tracker = instance_double(ChatwootExceptionTracker, capture_exception: true)
channel.update!(last_synced_at: 2.hours.ago)
allow(channel).to receive(:fetch_reviews).and_return([review_payload])
allow(AppStore::ReviewBuilder).to receive(:new).and_return(review_builder)
allow(review_builder).to receive(:perform).and_raise(StandardError, 'bad review')
allow(ChatwootExceptionTracker).to receive(:new).and_return(exception_tracker)
expect { described_class.perform_now(channel) }
.not_to change(channel.reload, :last_synced_at)
end
it 'does not fetch reviews when the feature is disabled for the account' do