diff --git a/app/loader/SignalConsoApplicationLoader.scala b/app/loader/SignalConsoApplicationLoader.scala index 36631496..a78dfa0e 100644 --- a/app/loader/SignalConsoApplicationLoader.scala +++ b/app/loader/SignalConsoApplicationLoader.scala @@ -117,6 +117,7 @@ import sttp.client3.HttpClientFutureBackend import sttp.client3.SttpBackend import tasks.EngagementEmailTask import tasks.ExportReportsToSFTPTask +import tasks.ScheduledTask import tasks.account.InactiveAccountTask import tasks.account.InactiveDgccrfAccountReminderTask import tasks.account.InactiveDgccrfAccountRemoveTask @@ -979,28 +980,35 @@ class SignalConsoComponents( signalConsoReviewController ) - def scheduleTasks() = { - companyUpdateTask.schedule() - reportNotificationTask.schedule() - inactiveAccountTask.schedule() - engagementEmailTask.schedule() - exportReportsToSFTPTask.schedule() - reportClosureTask.schedule() - reportReminderTask.schedule() - orphanReportFileDeletionTask.schedule() - oldReportExportDeletionTask.schedule() - oldReportsRgpdDeletionTask.schedule() - if (applicationConfiguration.task.probe.active) { - probeOrchestrator.scheduleProbeTasks() - } - if (applicationConfiguration.task.sampleData.active) { - sampleDataGenerationTask.schedule() - } - subcategoryLabelTask.schedule() - companyAlbertLabelTask.schedule() - companyReportCountViewRefresherTask.schedule() - siretExtractionTask.schedule() - } + val allTasks: List[ScheduledTask] = + List( + List( + companyUpdateTask, + reportNotificationTask, + inactiveAccountTask, + engagementEmailTask, + exportReportsToSFTPTask, + reportClosureTask, + reportReminderTask, + orphanReportFileDeletionTask, + oldReportExportDeletionTask, + oldReportsRgpdDeletionTask, + subcategoryLabelTask, + companyAlbertLabelTask, + companyReportCountViewRefresherTask, + siretExtractionTask + ), + if (applicationConfiguration.task.probe.active) { + probeOrchestrator.buildAllTasks() + } else + Nil, + if (applicationConfiguration.task.sampleData.active) { + List(sampleDataGenerationTask) + } else Nil + ).flatten + + def scheduleTasks() = + allTasks.foreach(_.schedule()) override def config: Config = ConfigFactory.load() diff --git a/app/orchestrators/ProbeOrchestrator.scala b/app/orchestrators/ProbeOrchestrator.scala index c7594641..798534ba 100644 --- a/app/orchestrators/ProbeOrchestrator.scala +++ b/app/orchestrators/ProbeOrchestrator.scala @@ -79,8 +79,8 @@ class ProbeOrchestrator( }: Unit } - def scheduleProbeTasks(): Unit = { - val tasks = Seq( + def buildAllTasks(): List[ScheduledTask] = { + List( buildProbe( 100, "reponseconso_probe", @@ -324,7 +324,7 @@ class ProbeOrchestrator( .map(n => Some(n.toDouble)) ) ) - tasks.foreach(_.schedule()) + } private def buildProbeAtLeastOneReport( diff --git a/app/tasks/ScheduledTask.scala b/app/tasks/ScheduledTask.scala index 4b0ba2de..dea1220c 100644 --- a/app/tasks/ScheduledTask.scala +++ b/app/tasks/ScheduledTask.scala @@ -20,8 +20,8 @@ import scala.util.Failure import scala.util.Success abstract class ScheduledTask( - taskId: Int, - taskName: String, + val taskId: Int, + val taskName: String, taskRepository: TaskRepositoryInterface, actorSystem: ActorSystem, taskConfiguration: TaskConfiguration @@ -97,4 +97,5 @@ abstract class ScheduledTask( val nextRunApproximateTime = computeDateTimeCorrespondingToDelay(initialDelay) logger.info(s"Task $taskName scheduled for $nextRunApproximateTime (in $initialDelay) and then every $interval") } + } diff --git a/app/tasks/company/CompanyReportCountViewRefresherTask.scala b/app/tasks/company/CompanyReportCountViewRefresherTask.scala index 00af9d89..5ce64e99 100644 --- a/app/tasks/company/CompanyReportCountViewRefresherTask.scala +++ b/app/tasks/company/CompanyReportCountViewRefresherTask.scala @@ -20,7 +20,7 @@ class CompanyReportCountViewRefresherTask( )(implicit executionContext: ExecutionContext ) extends ScheduledTask( - 13, + 15, "company_report_count_view_refresher_task", taskRepository, actorSystem, diff --git a/test/tasks/TasksIdsSpec.scala b/test/tasks/TasksIdsSpec.scala new file mode 100644 index 00000000..2155ba73 --- /dev/null +++ b/test/tasks/TasksIdsSpec.scala @@ -0,0 +1,34 @@ +package tasks + +import org.specs2.matcher.FutureMatchers +import org.specs2.mutable +import utils.TestApp + +class TasksIdsSpec extends mutable.Specification with FutureMatchers { + + val (app, components) = TestApp.buildApp() + + "All scheduled tasks" should { + "should not have duplicated taskId" in { + val tasksids = components.allTasks.map(_.taskId) + val duplicates = tasksids + .groupBy(identity) + .collect { + case (value, occurrences) if occurrences.size > 1 => value + } + .toList + duplicates shouldEqual Nil + } + + "should not have duplicated taskNames" in { + val taskNames = components.allTasks.map(_.taskName) + val duplicates = taskNames + .groupBy(identity) + .collect { + case (value, occurrences) if occurrences.size > 1 => value + } + .toList + duplicates shouldEqual Nil + } + } +}