From 47ca4317e3dce83ec5abbf86406dece23e3bf6ae Mon Sep 17 00:00:00 2001 From: Jon Alberdi Date: Tue, 23 Jul 2019 17:48:42 +0200 Subject: [PATCH] Add longRunningId to SchedulingContext Add a method to get an id to identify a context across reboots of the application. --- core/src/it/scala/com/criteo/cuttle/TestScheduling.scala | 1 + core/src/main/scala/com/criteo/cuttle/Scheduling.scala | 3 +++ core/src/test/scala/com/criteo/cuttle/TestScheduling.scala | 1 + cron/src/main/scala/com/criteo/cuttle/cron/CronModel.scala | 2 ++ .../com/criteo/cuttle/examples/HelloCustomScheduling.scala | 2 ++ .../com/criteo/cuttle/timeseries/TimeSeriesScheduler.scala | 4 ++++ 6 files changed, 13 insertions(+) diff --git a/core/src/it/scala/com/criteo/cuttle/TestScheduling.scala b/core/src/it/scala/com/criteo/cuttle/TestScheduling.scala index ededc3497..9e4796bf7 100644 --- a/core/src/it/scala/com/criteo/cuttle/TestScheduling.scala +++ b/core/src/it/scala/com/criteo/cuttle/TestScheduling.scala @@ -18,6 +18,7 @@ trait TestScheduling { val toJson: Json = Json.Null val log: ConnectionIO[String] = "id".pure[ConnectionIO] def compareTo(other: SchedulingContext) = 0 + override def longRunningId(): String = toString } case class TestScheduling(config: Unit = ()) extends Scheduling { diff --git a/core/src/main/scala/com/criteo/cuttle/Scheduling.scala b/core/src/main/scala/com/criteo/cuttle/Scheduling.scala index 6e811b2ad..001744f15 100644 --- a/core/src/main/scala/com/criteo/cuttle/Scheduling.scala +++ b/core/src/main/scala/com/criteo/cuttle/Scheduling.scala @@ -56,6 +56,9 @@ trait SchedulingContext { /** Compare to another context. In the current design only context of the same types will be * compared to each other because a workflow/project is defined for a single [[Scheduling]] type. */ def compareTo(other: SchedulingContext): Int + + /** An id to identify a context after a reboot of the application */ + def longRunningId(): String } /** Utilities for [[SchedulingContext]] */ diff --git a/core/src/test/scala/com/criteo/cuttle/TestScheduling.scala b/core/src/test/scala/com/criteo/cuttle/TestScheduling.scala index 131d46be3..d058d0b4d 100644 --- a/core/src/test/scala/com/criteo/cuttle/TestScheduling.scala +++ b/core/src/test/scala/com/criteo/cuttle/TestScheduling.scala @@ -20,6 +20,7 @@ trait TestScheduling { val toJson: Json = Json.Null val log: ConnectionIO[String] = "id".pure[ConnectionIO] def compareTo(other: SchedulingContext) = 0 + override def longRunningId(): String = toString } case class TestScheduling(config: Unit = ()) extends Scheduling { diff --git a/cron/src/main/scala/com/criteo/cuttle/cron/CronModel.scala b/cron/src/main/scala/com/criteo/cuttle/cron/CronModel.scala index fb9506e64..67b9d1d65 100644 --- a/cron/src/main/scala/com/criteo/cuttle/cron/CronModel.scala +++ b/cron/src/main/scala/com/criteo/cuttle/cron/CronModel.scala @@ -134,6 +134,8 @@ case class CronContext(instant: Instant)(retryNum: Int) extends SchedulingContex } override def asJson: Json = CronContext.encoder(this) + + override def longRunningId(): String = toString } case object CronContext { diff --git a/examples/src/main/scala/com/criteo/cuttle/examples/HelloCustomScheduling.scala b/examples/src/main/scala/com/criteo/cuttle/examples/HelloCustomScheduling.scala index abba97a10..a8348953c 100644 --- a/examples/src/main/scala/com/criteo/cuttle/examples/HelloCustomScheduling.scala +++ b/examples/src/main/scala/com/criteo/cuttle/examples/HelloCustomScheduling.scala @@ -48,6 +48,8 @@ object HelloCustomScheduling { case LoopContext(otherIteration) => iteration - otherIteration } + + override def longRunningId(): String = toString } // This our scheduling definition and configuration. For example diff --git a/timeseries/src/main/scala/com/criteo/cuttle/timeseries/TimeSeriesScheduler.scala b/timeseries/src/main/scala/com/criteo/cuttle/timeseries/TimeSeriesScheduler.scala index e75fa3b4b..eda7b5a37 100644 --- a/timeseries/src/main/scala/com/criteo/cuttle/timeseries/TimeSeriesScheduler.scala +++ b/timeseries/src/main/scala/com/criteo/cuttle/timeseries/TimeSeriesScheduler.scala @@ -265,6 +265,10 @@ case class TimeSeriesContext(start: Instant, thisBackfillPriority.compareTo(otherBackfillPriority) } } + + override def longRunningId(): String = { + (start, end, backfill).toString + } } object TimeSeriesContext {