Closed yawaramin closed 6 years ago
Parametrizing the start on "size of time period" would be a good idea.
If it's daily, then next day. If it's weekly, next week. If it's monthly, next month (with proper handling of edge cases).
Looking at Google /outlook event recurrence patterns, would give you a fairly complete picture (of cases to handle) as well as possible strategies for handling said edge cases.
@suhailshergill good point. The current signature of nextProcessingDate
is basically telling me, 'give me the next processing date based purely on the last completed date'. In the StagedProcess
trait, I don't have access to any recurrence information. I may be able to stick closely to the current API and default behaviour by adding a def recurrence: scala.concurrent.duration.Duration
method to the trait, e.g.
import scala.concurrent.duration.DurationInt
trait StagedProcess extends EigenflowDSL {
def executionPlan: ExecutionPlan[_, _]
def initialProcessingDate: Date = new Date()
def recurrence: Duration = 1.day
def nextProcessingDate(lastCompleted: Date): Date =
/*
lastCompleted rounded down to nearest recurrence unit + recurrence
e.g. if recurrence is 1h and lastCompleted is 16:55,
nextProcessingDate = 16:55 round down to 16:00 + 1h = 17:00
*/
}
java.time
FTW if going down the sensible default route:
scala> import java.time.temporal.ChronoUnit.DAYS
import java.time.temporal.ChronoUnit.DAYS
scala> import java.util.Date
import java.util.Date
scala> val d = new Date().toInstant
d: java.time.Instant = 2016-12-09T04:18:05.066Z
scala> d -> d.plus(1, DAYS).truncatedTo(DAYS)
res8: (java.time.Instant, java.time.Instant) = (2016-12-09T04:18:05.066Z,2016-12-10T00:00:00Z)
Also to note that the recurrence is already there in the Chronos job config.
@jonas agreed, java.time
FTW. I forgot that we have minimum JVM version at 1.8.
About the recurrence in Chronos, correct me if I'm wrong, but Eigenflow is not necessarily tied to Chronos. Although it's true that we can try to model recurrence
after Chronos' recurrence capabilities to make interop with Chronos easier. I'll have to read up on that.
In the majority of cases, we just want it to be the start of the next day. This should save a lot of boilerplate in jobs derived from
StagedProcess
. One way to do this using only Java standard date/time APIs (extract from REPL):