Skip to content

Commit

Permalink
Use separate queues for mailer scheduler and updater
Browse files Browse the repository at this point in the history
  • Loading branch information
wmnnd committed Dec 15, 2024
1 parent ad993d3 commit 9dbc2d5
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
6 changes: 4 additions & 2 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,17 @@ config :phoenix, :json_library, Jason
config :keila, Oban,
queues: [
mailer: 50,
periodic: 1
mailer_scheduler: 1,
updater: 1
],
repo: Keila.Repo,
plugins: [
{Oban.Plugins.Pruner, max_age: 1800},
{Oban.Plugins.Cron,
crontab: [
{"* * * * *", Keila.Mailings.DeliverScheduledCampaignsWorker},
{"* * * * *", Keila.Mailings.ScheduleWorker}
{"* * * * *", Keila.Mailings.ScheduleWorker},
{"0 0 * * *", Keila.Instance.UpdateCronWorker}
]}
]

Expand Down
2 changes: 1 addition & 1 deletion lib/keila/instance/update_cron_worker.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Keila.Instance.UpdateCronWorker do
use Oban.Worker,
queue: :periodic,
queue: :updater,
unique: [
period: :infinity,
states: [:available, :scheduled, :executing]
Expand Down
2 changes: 1 addition & 1 deletion lib/keila/mailings/deliver_scheduled_campaigns_worker.ex
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/keila/mailings/schedule_worker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule Keila.Mailings.ScheduleWorker do
"""

use Oban.Worker,
queue: :periodic,
queue: :mailer_scheduler,
unique: [
period: :infinity,
states: [:available, :scheduled, :executing]
Expand Down
12 changes: 6 additions & 6 deletions test/keila/mailings/mailings_campaign_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
File renamed without changes.

0 comments on commit 9dbc2d5

Please sign in to comment.