Skip to content

Commit a3ef0f6

Browse files
committed
fix: scheduled sync not syncing anymore from previous status fix
1 parent a4015c8 commit a3ef0f6

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

lib/fuzzy_catalog/catalog/external_library_sync.ex

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ defmodule FuzzyCatalog.Catalog.ExternalLibrarySync do
2525
"Starting sync with #{length(providers)} provider(s): #{Enum.join(Enum.map(providers, & &1.provider_name()), ", ")}"
2626
)
2727

28-
results = Enum.map(providers, &sync_provider/1)
28+
results = Enum.map(providers, &sync_provider_with_start/1)
2929

3030
summary = %{
3131
providers: Enum.map(providers, & &1.provider_name()),
@@ -39,8 +39,37 @@ defmodule FuzzyCatalog.Catalog.ExternalLibrarySync do
3939
end
4040
end
4141

42+
@doc """
43+
Synchronize books from a specific provider, calling start_sync first.
44+
This is used by sync_all_providers for scheduled syncs.
45+
"""
46+
def sync_provider_with_start(provider_module) do
47+
provider_name = provider_module.provider_name()
48+
49+
case SyncStatusManager.start_sync(provider_name) do
50+
:ok ->
51+
Logger.info("ExternalLibrarySync: Started sync status for #{provider_name}")
52+
sync_provider(provider_module)
53+
54+
{:error, :already_syncing} ->
55+
Logger.warning(
56+
"ExternalLibrarySync: Provider #{provider_name} is already syncing, skipping"
57+
)
58+
59+
error_stats = %{
60+
provider: provider_name,
61+
total_books: 0,
62+
new_books: 0,
63+
errors: ["Provider is already syncing"]
64+
}
65+
66+
{provider_module, error_stats}
67+
end
68+
end
69+
4270
@doc """
4371
Synchronize books from a specific provider using streaming for efficient memory usage.
72+
Assumes start_sync has already been called (used by AdminLive).
4473
"""
4574
def sync_provider(provider_module) do
4675
provider_name = provider_module.provider_name()

0 commit comments

Comments
 (0)