首页 > 解决方案 > How do you use cron jobs using Elastic Beanstalk and Java?

问题描述

I want to run cron jobs and use the same code base. I found a few solutions, but they don't appear ideal. For example, with Heroku, you can add a Scheduler element and fill in the commands to run in a web page.

This may also belong on SoftwareEngineering.StackExchange.

标签: javaamazon-web-servicesspring-bootcronamazon-elastic-beanstalk

解决方案


使用其他 AWS 系统有一种简单的方法可以做到这一点。

您可以使用 CloudWatch 设置计划事件 ( https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/WhatIsCloudWatchEvents.html )。您可以设置规则以按既定时间表设置事件。

然后,您至少有两个选择:

  • 将事件设置为发布 SNS 消息并使用该 SNS 在您的服务器上调用 Web 挂钩。关于如何执行此操作的许多示例,但您必须确保检查签名以确保从签名的 SNS 调用 Web API。但这将使用公共 API,可能不是您喜欢的。

  • 设置事件以发布 SQS 消息。然后设置一个弹性 beanstalk worker 来处理 SQS 消息,或者只是在你的主服务器上运行一个后台脚本,这基本上是一个无限循环轮询 SQS 的工作。

不确定您对这些系统的熟悉程度,因此不确定是否清楚我在说什么,但没有办法给出详细的解决方案,所以希望这足以给您提供想法。


推荐阅读