Skip to content

Commit

Permalink
fix duplicated taskId, and add test to prevent it happening again
Browse files Browse the repository at this point in the history
  • Loading branch information
eletallbetagouv committed Feb 4, 2025
1 parent b22ae5a commit cba388c
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 28 deletions.
52 changes: 30 additions & 22 deletions app/loader/SignalConsoApplicationLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down
6 changes: 3 additions & 3 deletions app/orchestrators/ProbeOrchestrator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ class ProbeOrchestrator(
}: Unit
}

def scheduleProbeTasks(): Unit = {
val tasks = Seq(
def buildAllTasks(): List[ScheduledTask] = {
List(
buildProbe(
100,
"reponseconso_probe",
Expand Down Expand Up @@ -324,7 +324,7 @@ class ProbeOrchestrator(
.map(n => Some(n.toDouble))
)
)
tasks.foreach(_.schedule())

}

private def buildProbeAtLeastOneReport(
Expand Down
5 changes: 3 additions & 2 deletions app/tasks/ScheduledTask.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CompanyReportCountViewRefresherTask(
)(implicit
executionContext: ExecutionContext
) extends ScheduledTask(
13,
15,
"company_report_count_view_refresher_task",
taskRepository,
actorSystem,
Expand Down
34 changes: 34 additions & 0 deletions test/tasks/TasksIdsSpec.scala
Original file line number Diff line number Diff line change
@@ -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
}
}
}

0 comments on commit cba388c

Please sign in to comment.