mirror of
https://github.com/we-promise/sure
synced 2026-04-25 17:15:07 +02:00
Handle duplicate sync jobs
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user