Sketch a scheduler for running periodic tasks

Periodic tasks are special in that they are usually kept around and
started based on a schedule. A new component checks periodic tasks and
submits them in the queue once they are due.

In order to avoid duplicate periodic jobs, the tracker of a job is
used to store the periodic job id. Each time a periodic task is due,
it is first checked if there is a job running (or queued) for this
task.
This commit is contained in:
Eike Kettner
2020-03-08 02:48:47 +01:00
parent 9b28858d06
commit 1e598bd902
20 changed files with 592 additions and 13 deletions

View File

@ -0,0 +1,28 @@
package docspell.common
import scodec.bits.ByteVector
import java.nio.charset.StandardCharsets
final class Hash(bytes: ByteVector) {
private def digest(name: String): String =
bytes.digest(name).toHex.toLowerCase
def sha256: String =
digest("SHA-256")
def md5: String =
digest("MD5")
def add(str: String): Hash =
new Hash(bytes ++ ByteVector.view(str.getBytes(StandardCharsets.UTF_8)))
def add(id: Ident): Hash =
add(id.id)
}
object Hash {
def empty: Hash = new Hash(ByteVector.empty)
}

View File

@ -4,6 +4,8 @@ import java.time.{Instant, LocalDate, ZoneId}
import cats.effect.Sync
import io.circe.{Decoder, Encoder}
import java.time.LocalDateTime
import java.time.ZonedDateTime
case class Timestamp(value: Instant) {
@ -17,13 +19,20 @@ case class Timestamp(value: Instant) {
def minusHours(n: Long): Timestamp =
Timestamp(value.minusSeconds(n * 60 * 60))
def toDate: LocalDate =
value.atZone(ZoneId.of("UTC")).toLocalDate
def toUtcDate: LocalDate =
value.atZone(Timestamp.UTC).toLocalDate
def toUtcDateTime: LocalDateTime =
value.atZone(Timestamp.UTC).toLocalDateTime
def atZone(zone: ZoneId): ZonedDateTime =
value.atZone(zone)
def asString: String = value.toString
}
object Timestamp {
val UTC = ZoneId.of("UTC")
val Epoch = Timestamp(Instant.EPOCH)