Skip to content

Commit

Permalink
Move job to Oban
Browse files Browse the repository at this point in the history
  • Loading branch information
vdegove committed Dec 16, 2024
1 parent b19f775 commit 32a3697
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
9 changes: 9 additions & 0 deletions apps/transport/lib/jobs/outdated_data_notification_job.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule Transport.Jobs.OutdatedDataNotificationJob do
use Oban.Worker, max_attempts: 3, tags: ["notifications"]

@impl Oban.Worker

def perform(%Oban.Job{id: job_id}) do
Transport.DataChecker.outdated_data(job_id)
end
end
6 changes: 1 addition & 5 deletions apps/transport/lib/transport/data_checker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,7 @@ defmodule Transport.DataChecker do
)
end

def outdated_data do
# Generated as an integer rather than a UUID because `payload.job_id`
# for other notifications are %Oban.Job.id (bigint).
job_id = Enum.random(1..Integer.pow(2, 63))

def outdated_data(job_id) do
for delay <- possible_delays(),
date = Date.add(Date.utc_today(), delay) do
{delay, gtfs_datasets_expiring_on(date)}
Expand Down
2 changes: 0 additions & 2 deletions apps/transport/lib/transport/scheduler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ defmodule Transport.Scheduler do
[
# Every day at 4am UTC
{"0 4 * * *", {Transport.ImportData, :import_validate_all, []}},
# Send email for outdated data
{"@daily", {Transport.DataChecker, :outdated_data, []}},
# Set inactive data
{"@daily", {Transport.DataChecker, :inactive_data, []}},
# Watch for new comments on datasets
Expand Down
4 changes: 2 additions & 2 deletions apps/transport/test/transport/data_checker_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ defmodule Transport.DataCheckerTest do
dataset_id: dataset.id
})

Transport.DataChecker.outdated_data()
Transport.DataChecker.outdated_data(42)

# a first mail to our team

Expand Down Expand Up @@ -271,7 +271,7 @@ defmodule Transport.DataCheckerTest do
end

test "outdated_data job with nothing to send should not send email" do
Transport.DataChecker.outdated_data()
Transport.DataChecker.outdated_data(42)
assert_no_email_sent()
end
end
Expand Down
3 changes: 2 additions & 1 deletion config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ oban_prod_crontab = [
{"30 5 * * *", Transport.Jobs.ImportDatasetMonthlyMetricsJob},
{"45 5 * * *", Transport.Jobs.ImportResourceMonthlyMetricsJob},
{"0 8 * * *", Transport.Jobs.WarnUserInactivityJob},
{"*/5 * * * *", Transport.Jobs.UpdateCounterCacheJob}
{"*/5 * * * *", Transport.Jobs.UpdateCounterCacheJob},
{"0 0 * * *", Transport.Jobs.OutdatedDataNotificationJob}
]

# Make sure that all modules exist
Expand Down

0 comments on commit 32a3697

Please sign in to comment.