diff --git a/app/jobs/inboxes/fetch_app_store_reviews_job.rb b/app/jobs/inboxes/fetch_app_store_reviews_job.rb index d90fc05d4..87732162c 100644 --- a/app/jobs/inboxes/fetch_app_store_reviews_job.rb +++ b/app/jobs/inboxes/fetch_app_store_reviews_job.rb @@ -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 diff --git a/db/migrate/20260522080000_repurpose_message_reply_to_flag_for_channel_app_store.rb b/db/migrate/20260522080000_repurpose_message_reply_to_flag_for_channel_app_store.rb index 3af1faac7..191bb7266 100644 --- a/db/migrate/20260522080000_repurpose_message_reply_to_flag_for_channel_app_store.rb +++ b/db/migrate/20260522080000_repurpose_message_reply_to_flag_for_channel_app_store.rb @@ -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 diff --git a/spec/jobs/inboxes/fetch_app_store_reviews_job_spec.rb b/spec/jobs/inboxes/fetch_app_store_reviews_job_spec.rb index e67c0d403..3779e34d7 100644 --- a/spec/jobs/inboxes/fetch_app_store_reviews_job_spec.rb +++ b/spec/jobs/inboxes/fetch_app_store_reviews_job_spec.rb @@ -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