mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +00:00
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:
28
modules/common/src/main/scala/docspell/common/Hash.scala
Normal file
28
modules/common/src/main/scala/docspell/common/Hash.scala
Normal 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)
|
||||
|
||||
}
|
@ -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)
|
||||
|
||||
|
Reference in New Issue
Block a user