This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
defmodule DecentralisedBookIndex.SyncTasks.SyncAuthorsTask do
|
||||
alias DecentralisedBookIndex.Sync.ApiClients.FetchJsons
|
||||
alias DecentralisedBookIndex.Sync.DataTransformers.AuthorTransformer
|
||||
alias DecentralisedBookIndex.Sync.AuthorSync
|
||||
|
||||
def sync(endpoint) do
|
||||
url = "#{endpoint}/api/v1/json/author"
|
||||
FetchJsons.get(url, &sync_author_chunk/1)
|
||||
endpoint
|
||||
end
|
||||
|
||||
def sync_author_chunk(json_chunk) do
|
||||
for json <- json_chunk do
|
||||
with {:ok, attrs} <- AuthorTransformer.from_json(json),
|
||||
:ok <- AuthorSync.create_update(attrs) do
|
||||
:ok
|
||||
else
|
||||
{:error, reason} ->
|
||||
Logger.error("Pipeline error: #{inspect(reason)}")
|
||||
end
|
||||
end
|
||||
|
||||
[]
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user