Akka Stream - 像 CRON 这样的计时器或调度程序
Akka Stream - Timer or Scheduler like CRON
我在 Scala 上使用 Akka Stream。 我想设置一个在每个 24:00 上运行的调度程序。我试图寻找它。但是我找不到我想做的事。能告诉我怎么写代码吗?
最常用的是akka quartz scheduler:
https://github.com/enragedginger/akka-quartz-scheduler
这是我写的,没有额外的依赖,比使用 quartz 更轻量一些,花里胡哨的东西更少:
https://github.com/johanandren/akron
使用 Akka 调度程序中的构建,请参阅:
http://doc.akka.io/docs/akka/current/scala/scheduler.html
您可以像这样使用调度程序:
system.scheduler.schedule(
initialDelay = FiniteDuration(/*offset to next 24:00*/),
interval = FiniteDuration(24, TimeUnit.HOURS),
receiver = self,
message = ScheduleAkkaStream
)
然后在 actor 中,当接收到 ScheduleAkkaStream 时,运行 作业
评论中提到了这一点,但实际上应该是仅使用 akka-streams 的首选解决方案:
Source.tick(0.seconds, 24.hours, Done).runForeach { x =>
//do something
}
我用过:
system.scheduler.scheduleWithFixedDelay(10.seconds, 30.seconds)(
() => {
println("Action")
}
)
我在 Scala 上使用 Akka Stream。 我想设置一个在每个 24:00 上运行的调度程序。我试图寻找它。但是我找不到我想做的事。能告诉我怎么写代码吗?
最常用的是akka quartz scheduler: https://github.com/enragedginger/akka-quartz-scheduler
这是我写的,没有额外的依赖,比使用 quartz 更轻量一些,花里胡哨的东西更少: https://github.com/johanandren/akron
使用 Akka 调度程序中的构建,请参阅: http://doc.akka.io/docs/akka/current/scala/scheduler.html
您可以像这样使用调度程序:
system.scheduler.schedule(
initialDelay = FiniteDuration(/*offset to next 24:00*/),
interval = FiniteDuration(24, TimeUnit.HOURS),
receiver = self,
message = ScheduleAkkaStream
)
然后在 actor 中,当接收到 ScheduleAkkaStream 时,运行 作业
评论中提到了这一点,但实际上应该是仅使用 akka-streams 的首选解决方案:
Source.tick(0.seconds, 24.hours, Done).runForeach { x =>
//do something
}
我用过:
system.scheduler.scheduleWithFixedDelay(10.seconds, 30.seconds)(
() => {
println("Action")
}
)