From 9dbc2d52238c8581da6fb70d45568789b80e57aa Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 15 Dec 2024 14:13:37 +0100 Subject: [PATCH] Use separate queues for mailer scheduler and updater --- config/config.exs | 6 ++++-- lib/keila/instance/update_cron_worker.ex | 2 +- .../mailings/deliver_scheduled_campaigns_worker.ex | 2 +- lib/keila/mailings/schedule_worker.ex | 2 +- test/keila/mailings/mailings_campaign_test.exs | 12 ++++++------ .../{rate_limiter_test.ex => rate_limiter_test.exs} | 0 6 files changed, 13 insertions(+), 11 deletions(-) rename test/keila/mailings/{rate_limiter_test.ex => rate_limiter_test.exs} (100%) diff --git a/config/config.exs b/config/config.exs index 7301b2aa..c9693eeb 100644 --- a/config/config.exs +++ b/config/config.exs @@ -84,7 +84,8 @@ config :phoenix, :json_library, Jason config :keila, Oban, queues: [ mailer: 50, - periodic: 1 + mailer_scheduler: 1, + updater: 1 ], repo: Keila.Repo, plugins: [ @@ -92,7 +93,8 @@ config :keila, Oban, {Oban.Plugins.Cron, crontab: [ {"* * * * *", Keila.Mailings.DeliverScheduledCampaignsWorker}, - {"* * * * *", Keila.Mailings.ScheduleWorker} + {"* * * * *", Keila.Mailings.ScheduleWorker}, + {"0 0 * * *", Keila.Instance.UpdateCronWorker} ]} ] diff --git a/lib/keila/instance/update_cron_worker.ex b/lib/keila/instance/update_cron_worker.ex index 3e0ad2e2..164b35c2 100644 --- a/lib/keila/instance/update_cron_worker.ex +++ b/lib/keila/instance/update_cron_worker.ex @@ -1,6 +1,6 @@ defmodule Keila.Instance.UpdateCronWorker do use Oban.Worker, - queue: :periodic, + queue: :updater, unique: [ period: :infinity, states: [:available, :scheduled, :executing] diff --git a/lib/keila/mailings/deliver_scheduled_campaigns_worker.ex b/lib/keila/mailings/deliver_scheduled_campaigns_worker.ex index c4f8e537..78ebe7bb 100644 --- a/lib/keila/mailings/deliver_scheduled_campaigns_worker.ex +++ b/lib/keila/mailings/deliver_scheduled_campaigns_worker.ex @@ -1,5 +1,5 @@ defmodule Keila.Mailings.DeliverScheduledCampaignsWorker do - use Oban.Worker, queue: :periodic + use Oban.Worker, queue: :mailer_scheduler alias Keila.Mailings def perform(%Oban.Job{}) do diff --git a/lib/keila/mailings/schedule_worker.ex b/lib/keila/mailings/schedule_worker.ex index efd10821..b402ab3a 100644 --- a/lib/keila/mailings/schedule_worker.ex +++ b/lib/keila/mailings/schedule_worker.ex @@ -7,7 +7,7 @@ defmodule Keila.Mailings.ScheduleWorker do """ use Oban.Worker, - queue: :periodic, + queue: :mailer_scheduler, unique: [ period: :infinity, states: [:available, :scheduled, :executing] diff --git a/test/keila/mailings/mailings_campaign_test.exs b/test/keila/mailings/mailings_campaign_test.exs index 36000710..f34a803b 100644 --- a/test/keila/mailings/mailings_campaign_test.exs +++ b/test/keila/mailings/mailings_campaign_test.exs @@ -83,7 +83,7 @@ defmodule Keila.MailingsCampaignTest do assert :ok = Mailings.deliver_campaign(campaign.id) - assert %{success: 1} = Oban.drain_queue(queue: :periodic) + assert %{success: 1} = Oban.drain_queue(queue: :mailer_scheduler) assert %{success: ^n, failure: 0} = Oban.drain_queue(queue: :mailer, with_scheduled: true) for _ <- 1..n do @@ -122,7 +122,7 @@ defmodule Keila.MailingsCampaignTest do assert :ok = Mailings.deliver_campaign(campaign.id) - assert %{success: 1} = Oban.drain_queue(queue: :periodic) + assert %{success: 1} = Oban.drain_queue(queue: :mailer_scheduler) assert %{success: ^n_expected_sent, failure: 0, snoozed: ^n_expected_snoozed} = Oban.drain_queue(queue: :mailer, with_scheduled: true) @@ -161,7 +161,7 @@ defmodule Keila.MailingsCampaignTest do assert :ok = Mailings.deliver_campaign(campaign.id) - assert %{success: 1} = Oban.drain_queue(queue: :periodic) + assert %{success: 1} = Oban.drain_queue(queue: :mailer_scheduler) assert %{success: ^n, failure: 0} = Oban.drain_queue(queue: :mailer, with_scheduled: true) for _ <- 1..n do @@ -186,7 +186,7 @@ defmodule Keila.MailingsCampaignTest do assert :ok = Mailings.deliver_campaign(campaign.id) - assert %{success: 1} = Oban.drain_queue(queue: :periodic) + assert %{success: 1} = Oban.drain_queue(queue: :mailer_scheduler) assert %{success: ^n, failure: 0} = Oban.drain_queue(queue: :mailer, with_scheduled: true) for _ <- 1..n do @@ -308,7 +308,7 @@ defmodule Keila.MailingsCampaignTest do ) assert :ok = Mailings.deliver_campaign(campaign.id) - assert %{success: 1} = Oban.drain_queue(queue: :periodic) + assert %{success: 1} = Oban.drain_queue(queue: :mailer_scheduler) assert %{success: 1, failure: 0} = Oban.drain_queue(queue: :mailer, with_scheduled: true) receive do @@ -343,7 +343,7 @@ defmodule Keila.MailingsCampaignTest do assert :ok = Mailings.deliver_campaign(campaign.id) - assert %{success: 1} = Oban.drain_queue(queue: :periodic) + assert %{success: 1} = Oban.drain_queue(queue: :mailer_scheduler) assert %{success: 1, cancelled: 1} = Oban.drain_queue(queue: :mailer, with_scheduled: true) assert %{status: :sent} = Mailings.get_campaign_stats(campaign.id) end diff --git a/test/keila/mailings/rate_limiter_test.ex b/test/keila/mailings/rate_limiter_test.exs similarity index 100% rename from test/keila/mailings/rate_limiter_test.ex rename to test/keila/mailings/rate_limiter_test.exs