Skip to content

Commit

Permalink
Rename OutdatedDataJob to ExpirationAdminProducerJob to show proximit…
Browse files Browse the repository at this point in the history
…y with reuser job
  • Loading branch information
vdegove committed Dec 17, 2024
1 parent d61bb63 commit d278d6c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
defmodule Transport.Jobs.OutdatedDataNotificationJob do
defmodule Transport.Jobs.ExpirationAdminProducerNotificationJob do
@moduledoc """
This module is in charge of sending notifications to both admins and users when data is outdated.
This module is in charge of sending notifications to admins and producers when data is outdated.
It is similar to `Transport.Jobs.ExpirationNotificationJob`, dedicated to reusers.
Both could be merged in the future.
"""

use Oban.Worker, max_attempts: 3, tags: ["notifications"]
Expand Down
2 changes: 2 additions & 0 deletions apps/transport/lib/jobs/expiration_notification_job.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ defmodule Transport.Jobs.ExpirationNotificationJob do
It has 2 `perform/1` methods:
- a dispatcher one in charge of identifying contacts we should get in touch with today
- another in charge of building the daily digest for a specific contact (with only their favorited datasets)
It is similar to `Transport.Jobs.ExpirationAdminProducerNotificationJob`, dedicated to producers and admins.
"""
use Oban.Worker,
max_attempts: 3,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Transport.Test.Transport.Jobs.OutdatedDataNotificationJobTest do
defmodule Transport.Test.Transport.Jobs.ExpirationAdminProducerNotificationJobTest do
use ExUnit.Case, async: true
import DB.Factory
import Swoosh.TestAssertions
Expand Down Expand Up @@ -30,7 +30,7 @@ defmodule Transport.Test.Transport.Jobs.OutdatedDataNotificationJobTest do
)

assert [{%DB.Dataset{id: ^dataset_id}, [%DB.Resource{id: ^resource_id}]}] =
Date.utc_today() |> Transport.Jobs.OutdatedDataNotificationJob.gtfs_datasets_expiring_on()
Date.utc_today() |> Transport.Jobs.ExpirationAdminProducerNotificationJob.gtfs_datasets_expiring_on()

%DB.Contact{id: contact_id, email: email} = contact = insert_contact()

Expand All @@ -54,7 +54,7 @@ defmodule Transport.Test.Transport.Jobs.OutdatedDataNotificationJobTest do
dataset_id: dataset.id
})

assert :ok == perform_job(Transport.Jobs.OutdatedDataNotificationJob, %{})
assert :ok == perform_job(Transport.Jobs.ExpirationAdminProducerNotificationJob, %{})

# a first mail to our team

Expand Down Expand Up @@ -106,13 +106,13 @@ defmodule Transport.Test.Transport.Jobs.OutdatedDataNotificationJobTest do
end

test "outdated_data job with nothing to send should not send email" do
assert :ok == perform_job(Transport.Jobs.OutdatedDataNotificationJob, %{})
assert :ok == perform_job(Transport.Jobs.ExpirationAdminProducerNotificationJob, %{})
assert_no_email_sent()
end

test "gtfs_datasets_expiring_on" do
{today, tomorrow, yesterday} = {Date.utc_today(), Date.add(Date.utc_today(), 1), Date.add(Date.utc_today(), -1)}
assert [] == today |> Transport.Jobs.OutdatedDataNotificationJob.gtfs_datasets_expiring_on()
assert [] == today |> Transport.Jobs.ExpirationAdminProducerNotificationJob.gtfs_datasets_expiring_on()

insert_fn = fn %Date{} = expiration_date, %DB.Dataset{} = dataset ->
multi_validation =
Expand All @@ -131,7 +131,7 @@ defmodule Transport.Test.Transport.Jobs.OutdatedDataNotificationJobTest do
insert_fn.(today, insert(:dataset, is_active: false))
insert_fn.(today, insert(:dataset, is_active: true, is_hidden: true))

assert [] == today |> Transport.Jobs.OutdatedDataNotificationJob.gtfs_datasets_expiring_on()
assert [] == today |> Transport.Jobs.ExpirationAdminProducerNotificationJob.gtfs_datasets_expiring_on()

# 2 GTFS resources expiring on the same day for a dataset
%DB.Dataset{id: dataset_id} = dataset = insert(:dataset, is_active: true)
Expand All @@ -141,23 +141,23 @@ defmodule Transport.Test.Transport.Jobs.OutdatedDataNotificationJobTest do
assert [
{%DB.Dataset{id: ^dataset_id},
[%DB.Resource{dataset_id: ^dataset_id}, %DB.Resource{dataset_id: ^dataset_id}]}
] = today |> Transport.Jobs.OutdatedDataNotificationJob.gtfs_datasets_expiring_on()
] = today |> Transport.Jobs.ExpirationAdminProducerNotificationJob.gtfs_datasets_expiring_on()

assert [] == tomorrow |> Transport.Jobs.OutdatedDataNotificationJob.gtfs_datasets_expiring_on()
assert [] == yesterday |> Transport.Jobs.OutdatedDataNotificationJob.gtfs_datasets_expiring_on()
assert [] == tomorrow |> Transport.Jobs.ExpirationAdminProducerNotificationJob.gtfs_datasets_expiring_on()
assert [] == yesterday |> Transport.Jobs.ExpirationAdminProducerNotificationJob.gtfs_datasets_expiring_on()

insert_fn.(tomorrow, dataset)

assert [
{%DB.Dataset{id: ^dataset_id},
[%DB.Resource{dataset_id: ^dataset_id}, %DB.Resource{dataset_id: ^dataset_id}]}
] = today |> Transport.Jobs.OutdatedDataNotificationJob.gtfs_datasets_expiring_on()
] = today |> Transport.Jobs.ExpirationAdminProducerNotificationJob.gtfs_datasets_expiring_on()

assert [
{%DB.Dataset{id: ^dataset_id}, [%DB.Resource{dataset_id: ^dataset_id}]}
] = tomorrow |> Transport.Jobs.OutdatedDataNotificationJob.gtfs_datasets_expiring_on()
] = tomorrow |> Transport.Jobs.ExpirationAdminProducerNotificationJob.gtfs_datasets_expiring_on()

assert [] == yesterday |> Transport.Jobs.OutdatedDataNotificationJob.gtfs_datasets_expiring_on()
assert [] == yesterday |> Transport.Jobs.ExpirationAdminProducerNotificationJob.gtfs_datasets_expiring_on()

# Multiple datasets
%DB.Dataset{id: d2_id} = d2 = insert(:dataset, is_active: true)
Expand All @@ -167,6 +167,6 @@ defmodule Transport.Test.Transport.Jobs.OutdatedDataNotificationJobTest do
{%DB.Dataset{id: ^dataset_id},
[%DB.Resource{dataset_id: ^dataset_id}, %DB.Resource{dataset_id: ^dataset_id}]},
{%DB.Dataset{id: ^d2_id}, [%DB.Resource{dataset_id: ^d2_id}]}
] = today |> Transport.Jobs.OutdatedDataNotificationJob.gtfs_datasets_expiring_on()
] = today |> Transport.Jobs.ExpirationAdminProducerNotificationJob.gtfs_datasets_expiring_on()
end
end
6 changes: 3 additions & 3 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ oban_prod_crontab = [
{"0 6 * * 1-5", Transport.Jobs.NewDatagouvDatasetsJob, args: %{check_rules: true}},
{"5 6 * * 1-5", Transport.Jobs.NewDatagouvDatasetsJob},
{"0 6 * * *", Transport.Jobs.NewDatasetNotificationsJob},
{"30 6 * * *", Transport.Jobs.ExpirationNotificationJob},
{"30 6 * * *", Transport.Jobs.ExpirationAdminProducerNotificationJob},
{"45 6 * * *", Transport.Jobs.ExpirationNotificationJob},
{"0 8 * * 1-5", Transport.Jobs.NewCommentsNotificationJob},
{"0 21 * * *", Transport.Jobs.DatasetHistoryDispatcherJob},
# Should be executed after all `DatasetHistoryJob` have been executed
Expand All @@ -160,8 +161,7 @@ oban_prod_crontab = [
{"30 5 * * *", Transport.Jobs.ImportDatasetMonthlyMetricsJob},
{"45 5 * * *", Transport.Jobs.ImportResourceMonthlyMetricsJob},
{"0 8 * * *", Transport.Jobs.WarnUserInactivityJob},
{"*/5 * * * *", Transport.Jobs.UpdateCounterCacheJob},
{"0 0 * * *", Transport.Jobs.OutdatedDataNotificationJob}
{"*/5 * * * *", Transport.Jobs.UpdateCounterCacheJob}
]

# Make sure that all modules exist
Expand Down

0 comments on commit d278d6c

Please sign in to comment.