From d278d6c4387e516492c935a6b650c78138086e2a Mon Sep 17 00:00:00 2001 From: Vincent Degove Date: Tue, 17 Dec 2024 15:47:21 +0100 Subject: [PATCH] Rename OutdatedDataJob to ExpirationAdminProducerJob to show proximity with reuser job --- ...ration_admin_producer_notification_job.ex} | 6 +++-- .../lib/jobs/expiration_notification_job.ex | 2 ++ ..._admin_producer_notification_job_test.exs} | 26 +++++++++---------- config/runtime.exs | 6 ++--- 4 files changed, 22 insertions(+), 18 deletions(-) rename apps/transport/lib/jobs/{outdated_data_notification_job.ex => expiration_admin_producer_notification_job.ex} (90%) rename apps/transport/test/transport/jobs/{outdated_data_notification_job_test.exs => expiration_admin_producer_notification_job_test.exs} (81%) diff --git a/apps/transport/lib/jobs/outdated_data_notification_job.ex b/apps/transport/lib/jobs/expiration_admin_producer_notification_job.ex similarity index 90% rename from apps/transport/lib/jobs/outdated_data_notification_job.ex rename to apps/transport/lib/jobs/expiration_admin_producer_notification_job.ex index e5321d1cba..ad493add7b 100644 --- a/apps/transport/lib/jobs/outdated_data_notification_job.ex +++ b/apps/transport/lib/jobs/expiration_admin_producer_notification_job.ex @@ -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"] diff --git a/apps/transport/lib/jobs/expiration_notification_job.ex b/apps/transport/lib/jobs/expiration_notification_job.ex index e8cba3cf6f..09f4f0dfce 100644 --- a/apps/transport/lib/jobs/expiration_notification_job.ex +++ b/apps/transport/lib/jobs/expiration_notification_job.ex @@ -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, diff --git a/apps/transport/test/transport/jobs/outdated_data_notification_job_test.exs b/apps/transport/test/transport/jobs/expiration_admin_producer_notification_job_test.exs similarity index 81% rename from apps/transport/test/transport/jobs/outdated_data_notification_job_test.exs rename to apps/transport/test/transport/jobs/expiration_admin_producer_notification_job_test.exs index c83275757b..c456bace18 100644 --- a/apps/transport/test/transport/jobs/outdated_data_notification_job_test.exs +++ b/apps/transport/test/transport/jobs/expiration_admin_producer_notification_job_test.exs @@ -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 @@ -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() @@ -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 @@ -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 = @@ -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) @@ -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) @@ -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 diff --git a/config/runtime.exs b/config/runtime.exs index 59102d4062..19a851a01c 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -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 @@ -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