Skip to content

Latest commit

 

History

History
42 lines (34 loc) · 2.39 KB

README.md

File metadata and controls

42 lines (34 loc) · 2.39 KB

Sisyphus

A Scala scheduler that supports multiple cron notations. The project follows the Semantic Versioning Convention and uses Apache 2.0 license.

How to use it?

import com.cronutils.model.CronType
import com.cronutils.model.definition.CronDefinitionBuilder
import com.cronutils.parser.CronParser
import com.cronutils.sisyphus.model.{CronTask, Scheduler}
import org.joda.time.DateTime

val scheduler = new Scheduler()

//declare parsers and crons. We support parsing multiple cron formats!
val quartzparser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ))
val unixcronparser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.UNIX))
var qzcron = quartzparser.parse("*/5 * * * * ? *")
var nixcron = unixcronparser.parse("* * * * *")

//define tasks to be executed!
val qzcrontask = new CronTask("qztimeprinter") {
  override def execute(): Unit = println(s"We got a Quartz match! ${DateTime.now()}")
}
val nixcrontask = new CronTask("nixtimeprinter") {
  override def execute(): Unit = println(s"We got a Unix match! ${DateTime.now()}")
}

//schedule and enjoy!
scheduler.schedule(qzcron, qzcrontask)
scheduler.schedule(nixcron, nixcrontask)

Sisyphus leverages cron-utils library to parse cron expressions and find if a date matches it. You can use any cron-expression to schedule a task.

Resources