我的Play v2.6应用使用scheduled tasks。这些可以在本地运行,但在部署到Heroku时永远不会触发。
以前有与此相关的问题,但是没有一个相关的答案。
打印设置任务时的日志,但不显示执行任务时的日志消息。而且,执行任务的效果永远不会发生。
排定的时间是将来的1秒钟,因此Heroku没有机会让应用程序处于休眠状态。
来源:
@Singleton
class PaymentProcessor @Inject()(repo: PaymentRepo,
config: Configuration,
system: ActorSystem) {
private val actor = system.actorOf(Props(new ActorDef()))
private implicit val ec: ExecutionContextExecutor = system.dispatcher
def checkForPayments(reason: String, after: FiniteDuration = 1.second): Unit = {
Logger.debug(s"Checking again for due payments after $after")
system.scheduler.scheduleOnce(after, actor, CheckForPayments(reason))
}
class ActorDef() extends Actor {
override def receive: Receive = {
case CheckForPayments(reason) =>
Logger.debug(s"Checking for due payments ($reason)")
// followed by logic to find and transact due payments
}
}
本地输出:
[debug] application - Checking again for due payments after 1 second
[debug] application - Checking for due payments (CSV uploaded)
(在此之后,找到并处理应付款)
Heroku上的输出:
2018-11-18T11:48:01.247773+00:00 app[web.1]: [debug] application - Checking again for due payments after 1 second
(之后将不进行应付款)
这仅仅是Heroku免费套餐的限制吗?还是我可以配置一些东西?