[英]How do you use cron jobs using Elastic Beanstalk and Java?
I want to run cron jobs and use the same code base. 我想运行cron作业并使用相同的代码库。 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.
例如,使用Heroku,您可以添加Scheduler元素并填写要在网页中运行的命令。
require('async')
in Node, but what would be a Java Spring Boot equivalent? require('async')
,但是等效于Java Spring Boot? cron.yaml
which doesn't make sense as the app is deployed via a WAR/ZIP file to a Tomcat instance (Spring Boot). cron.yaml
,因为该应用程序是通过WAR / ZIP文件部署到Tomcat实例(Spring Boot)的,所以没有意义。 cron.yaml
. cron.yaml
。 This may also belong on SoftwareEngineering.StackExchange. 这也可能属于SoftwareEngineering.StackExchange。
There is an easy way to do this using other AWS systems. 使用其他AWS系统有一种简便的方法。
You can use CloudWatch to set scheduled events ( https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/WhatIsCloudWatchEvents.html ). 您可以使用CloudWatch设置计划的事件( https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/WhatIsCloudWatchEvents.html )。 You can set a rule to set the event on a set schedule.
您可以设置规则以按预定时间表设置事件。
You then have at least two options: 然后,您至少有两个选择:
set the event to publish an SNS message and use that SNS to call a web hook on your server. 将事件设置为发布SNS消息,并使用该SNS调用服务器上的Web挂钩。 Many examples on how to do this but you will have to make sure you check the signature to ensure the web API is called from the signed SNS.
有关如何执行此操作的许多示例,但是您必须确保检查签名以确保从已签名的SNS调用Web API。 But this would use a public API and may not be something you are comfortable with.
但这将使用公共API,但您可能不满意。
set the event to publish an SQS message. 设置事件以发布SQS消息。 Then set an elastic beanstalk worker to process the SQS message or just run a background script on your main server, which is basically on an infinite loop polling SQS for work to do.
然后设置一个弹性beantalk工作者来处理SQS消息,或者只在主服务器上运行后台脚本,该服务器基本上是在无限循环轮询SQS上进行的工作。
Not sure how familiar you are with these systems so not sure if it will be clear what I am talking about, but there is no way to give a detail solution so hope this is enough to give you ideas. 不确定您对这些系统有多熟悉,因此不确定是否可以清楚我在说什么,但是无法给出详细的解决方案,因此希望这足以为您提供想法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.