From dff915e835d9442e43555a3d795243537947656b Mon Sep 17 00:00:00 2001 From: KKlochko Date: Sun, 27 Apr 2025 14:07:57 +0300 Subject: [PATCH] Add the SyncWorker and its cron configuration for Oban. --- config/config.exs | 11 ++++++++++- .../sync/sync_workers/sync_worker.ex | 13 +++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 lib/decentralised_book_index/sync/sync_workers/sync_worker.ex 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