简体   繁体   English

如何使用Elastic Beanstalk和Java使用cron作业?

[英]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元素并填写要在网页中运行的命令。

  • http://blog.rotaready.com/scheduled-tasks-elastic-beanstalk-cron/ http://blog.rotaready.com/scheduled-tasks-elastic-beanstalk-cron/
    • It seems overly complicated for load-balanced instances. 对于负载平衡的实例,这似乎过于复杂。
    • It makes use of require('async') in Node, but what would be a Java Spring Boot equivalent? 它在Node中使用了require('async') ,但是等效于Java Spring Boot?
  • https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features-managing-env-tiers.html https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features-managing-env-tiers.html
    • There doesn't appear to be any security. 似乎没有任何安全性。 Any one the net could access the /path to POST and execute the job, causing a denial-of-service attack. 网络中的任何人都可以访问/ path来执行POST并执行作业,从而导致拒绝服务攻击。
    • it mentions 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)的,所以没有意义。
    • It mentions Amazon DynamoDB, which we don't use. 它提到了我们不使用的Amazon DynamoDB。 We use MySQL. 我们使用MySQL。
    • It doesn't specify whether the load balancer connection draining timeout is in effect for these jobs (10s). 它没有指定负载均衡器连接耗尽超时对于这些作业(10s)是否有效。
    • It mentions "Worker Configuration card on the Configuration page in the environment management console" but there is no Worker Configuration card under Configuration page. 它提到“环境管理控制台的“配置”页面上的“工作程序配置卡””,但在“配置”页面下没有工作程序配置卡。
  • Running a cron job in Elastic Beanstalk 在Elastic Beanstalk中运行cron作业
    • For Python/Django - uses cron.yaml . 对于Python / Django-使用cron.yaml
  • I thought of just having a dedicated EC2 instance, but how can I deploy the latest code changes there? 我想到只是有一个专用的EC2实例,但是如何在其中部署最新的代码更改?

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.

相关问题 如何使用 AWS CLI 2 将更新的 JAR 上传到现有的 Java Elastic Beanstalk 实例? - How do I upload an updated JAR to an existing Java Elastic Beanstalk instance using the AWS CLI 2? 如何使用附加到 Elastic Beanstalk 环境的 RDS 环境属性 - Java - How to use RDS environment properties attached to Elastic Beanstalk Environment - Java 如何使用Google DataProc Java客户端在相关的GS存储桶中使用jar文件和类提交spark作业? - How do you use the Google DataProc Java Client to submit spark jobs using jar files and classes in associated GS bucket? 您如何与在弹性beantalk上部署为工作线程的docker容器共享特权信息? - How do you share privileged information with a docker container deployed as a worker on elastic beanstalk? 如何让应用程序引擎cron作业显示在Web界面的“计划任务”选项卡中? - How do you get app engine cron jobs to show in “scheduled tasks” tab on the web interface? 如何从Spring Java Elastic Beanstalk应用程序连接到我的AWS DynamoDB实例? - How do I connect to my AWS DynamoDB instance from a Spring Java Elastic Beanstalk app? 如何将 LetsEncrypt SSL 安装到运行 Tomcat 8 和 Java 8 平台的 AWS Elastic Beanstalk 应用程序上 - How do I install LetsEncrypt SSL onto AWS Elastic Beanstalk application running Tomcat 8 with Java 8 Platform 使用 Spring WebSecurityConfigurerAdapter 时,如何让我的 Elastic Beanstalk 实例保持健康? - How do I keep my Elastic Beanstalk instance healthy when using Spring WebSecurityConfigurerAdapter? 结合使用AWS Elastic Beanstalk和Java / BlazeDS / Spring应用程序 - Using AWS Elastic Beanstalk with a Java/BlazeDS/Spring application 如何在AWS Elastic Beanstalk中托管Java TCP服务器 - How to host a Java TCP server in AWS Elastic Beanstalk
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM