diff --git a/config/config.exs b/config/config.exs index 672d78f..33ad87d 100644 --- a/config/config.exs +++ b/config/config.exs @@ -8,7 +8,16 @@ import Config config :ash_oban, pro?: false -config :decentralised_book_index, Oban, plugins: [{Oban.Plugins.Cron, []}] +config :decentralised_book_index, Oban, + repo: DecentralisedBookIndex.Repo, + queues: [default: 14], + plugins: [ + Oban.Plugins.Pruner, + {Oban.Plugins.Cron, + crontab: [ + {"@daily", DecentralisedBookIndex.SyncWorker}, + ]} + ] config :mime, extensions: %{"json" => "application/vnd.api+json"}, diff --git a/lib/decentralised_book_index/sync/sync_workers/sync_worker.ex b/lib/decentralised_book_index/sync/sync_workers/sync_worker.ex new file mode 100644 index 0000000..ffa130a --- /dev/null +++ b/lib/decentralised_book_index/sync/sync_workers/sync_worker.ex @@ -0,0 +1,13 @@ +defmodule DecentralisedBookIndex.SyncWorker do + use Oban.Worker, + queue: :default, + max_attempts: 2, + tags: ["sync", "cron"] + + require Logger + + @impl Oban.Worker + def perform(%Oban.Job{args: args} = job) do + SyncServerTask.sync_all() + end +end