akka 流的全功能 Cron 调度
Full featured Cron scheduling of akka streams
在 akka 流中可以执行以下操作:
Source.tick(0.seconds, 15.seconds, "Hello")
并且您的流将每 15 秒接收一次滴答元素 "Hello"。我正在寻找的是做同样的事情的可能性,但在类似 cron 的时间表上,例如"every monday at 5 pm".
我明白了。有一个 akka 插件 akka-quartz-scheduler 允许像这样配置一些 quartz 计划配置:将此部分添加到 akka.conf
akka {
quartz.schedules {
SomeSchedule {
expression = "0 0 1 * * ?"
timezone = "GMT-7"
description = "Do something every day at 1 a.m. SF time."
}
}
}
然后安排它
case class Signal(someData: String)
implicit val system: ActorSystem = ActorSystem("lebulbeaux-system")
implicit val materializer: ActorMaterializer = ActorMaterializer()
// needed for the future flatMap/onComplete in the end
implicit val executionContext: ExecutionContextExecutor = system.dispatcher
val source: Source[Signal, ActorRef] = Source.actorRef[Signal](100, OverflowStrategy.fail)
val ref: ActorRef = Flow[Signal].to(Sink.foreach(signal => println(signal.someData))).runWith(source)
import com.typesafe.akka.extension.quartz.QuartzSchedulerExtension
QuartzSchedulerExtension(system).schedule("SomeSchedule", ref, Signal("Hello!"))
// scroll
现在您每天 1 点 a.m 都会收到一条信号消息。顺丰时间.
此外,请查看此 以获得更多使用 Source.actorRef
的选项
在 akka 流中可以执行以下操作:
Source.tick(0.seconds, 15.seconds, "Hello")
并且您的流将每 15 秒接收一次滴答元素 "Hello"。我正在寻找的是做同样的事情的可能性,但在类似 cron 的时间表上,例如"every monday at 5 pm".
我明白了。有一个 akka 插件 akka-quartz-scheduler 允许像这样配置一些 quartz 计划配置:将此部分添加到 akka.conf
akka {
quartz.schedules {
SomeSchedule {
expression = "0 0 1 * * ?"
timezone = "GMT-7"
description = "Do something every day at 1 a.m. SF time."
}
}
}
然后安排它
case class Signal(someData: String)
implicit val system: ActorSystem = ActorSystem("lebulbeaux-system")
implicit val materializer: ActorMaterializer = ActorMaterializer()
// needed for the future flatMap/onComplete in the end
implicit val executionContext: ExecutionContextExecutor = system.dispatcher
val source: Source[Signal, ActorRef] = Source.actorRef[Signal](100, OverflowStrategy.fail)
val ref: ActorRef = Flow[Signal].to(Sink.foreach(signal => println(signal.someData))).runWith(source)
import com.typesafe.akka.extension.quartz.QuartzSchedulerExtension
QuartzSchedulerExtension(system).schedule("SomeSchedule", ref, Signal("Hello!"))
// scroll
现在您每天 1 点 a.m 都会收到一条信号消息。顺丰时间.
此外,请查看此