1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-23 15:19:38 +02:00

Handle duplicate sync jobs

This commit is contained in:
Zach Gollwitzer 2025-05-24 17:58:17 -04:00
parent aecb5aafd8
commit 5125411822
2 changed files with 17 additions and 0 deletions

View file

@ -57,6 +57,12 @@ class Sync < ApplicationRecord
def perform
Rails.logger.tagged("Sync", id, syncable_type, syncable_id) do
# This can happen on server restarts or if Sidekiq enqueues a duplicate job
unless may_start?
Rails.logger.warn("Sync #{id} is not in a valid state (#{aasm.from_state}) to start. Skipping sync.")
return
end
start!
begin

View file

@ -3,6 +3,17 @@ require "test_helper"
class SyncTest < ActiveSupport::TestCase
include ActiveJob::TestHelper
test "does not run if not in a valid state" do
syncable = accounts(:depository)
sync = Sync.create!(syncable: syncable, status: :completed)
syncable.expects(:perform_sync).never
sync.perform
assert_equal "completed", sync.status
end
test "runs successful sync" do
syncable = accounts(:depository)
sync = Sync.create!(syncable: syncable)