The personal finance app for everyone
Handle duplicate sync jobs
Zach Gollwitzer5125411822a4
diff --git a/app/models/sync.rb b/app/models/sync.rbindex be4bb8c3..37c05dfa 100644--- a/app/models/sync.rb+++ b/app/models/sync.rb@@ -57,6 +57,12 @@ class Sync < ApplicationRecorddef performRails.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!begindiff --git a/test/models/sync_test.rb b/test/models/sync_test.rbindex 05765ea0..d1182fd5 100644--- a/test/models/sync_test.rb+++ b/test/models/sync_test.rb@@ -3,6 +3,17 @@ require "test_helper"class SyncTest < ActiveSupport::TestCaseinclude 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" dosyncable = accounts(:depository)sync = Sync.create!(syncable: syncable)