feat(sync): enable scheduled asset synchronization mode
This update introduces a persistent background synchronization mode, allowing the external assets container to run continuously and periodically sync albums instead of executing once and exiting. The system now checks a configurable interval, retries on temporary failures, and manages its lifecycle using `time.sleep`. - Added SYNC_INTERVAL_SECONDS configuration for scheduling - Updated compose service to restart automatically and loop indefinitely - Implemented continuous run logic in main function and added corresponding unit tests
This commit is contained in:
@@ -174,6 +174,50 @@ class SynchronizationTests(unittest.TestCase):
|
||||
["asset-one", "asset-two"],
|
||||
)
|
||||
|
||||
def test_continuous_mode_waits_and_runs_again(self) -> None:
|
||||
with patch.object(
|
||||
album_sync,
|
||||
"SYNC_INTERVAL_SECONDS",
|
||||
1800,
|
||||
), patch.object(
|
||||
album_sync,
|
||||
"check_configuration",
|
||||
), patch.object(
|
||||
album_sync,
|
||||
"synchronize",
|
||||
side_effect=[None, KeyboardInterrupt],
|
||||
) as synchronize, patch.object(
|
||||
album_sync.time,
|
||||
"sleep",
|
||||
) as sleep:
|
||||
with self.assertRaises(KeyboardInterrupt):
|
||||
album_sync.main()
|
||||
|
||||
self.assertEqual(synchronize.call_count, 2)
|
||||
sleep.assert_called_once_with(1800)
|
||||
|
||||
def test_continuous_mode_retries_after_sync_error(self) -> None:
|
||||
with patch.object(
|
||||
album_sync,
|
||||
"SYNC_INTERVAL_SECONDS",
|
||||
1800,
|
||||
), patch.object(
|
||||
album_sync,
|
||||
"check_configuration",
|
||||
), patch.object(
|
||||
album_sync,
|
||||
"synchronize",
|
||||
side_effect=[RuntimeError("temporary"), KeyboardInterrupt],
|
||||
) as synchronize, patch.object(
|
||||
album_sync.time,
|
||||
"sleep",
|
||||
) as sleep:
|
||||
with self.assertRaises(KeyboardInterrupt):
|
||||
album_sync.main()
|
||||
|
||||
self.assertEqual(synchronize.call_count, 2)
|
||||
sleep.assert_called_once_with(1800)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user