英文:
Microservice for running cron job in spring boot application
问题
应用设计问题:
我有一个Spring Boot应用程序,我的任务是设计一个定时任务,每小时运行一次,从我们的RDS数据库中收集一些数据,并将其发送到共享的Redshift实例。Redshift实例由Mode Analytics工具使用,用于提取一些数据并为相关人员运行一些报告。
问题是:我是否应该为这个任务编写一个新的微服务?我们不希望这再成为我们应用的一部分,因为这个任务比较繁重,与实际应用无关。但是,如果我为此编写一个服务,在定时任务不运行并且浪费资源时,它将处于空闲状态。对于这个任务,AWS Lambda是否更好?
英文:
Application design question here :
I have a spring boot application and I am tasked with designing a cron job that will run every 1 hour, collect some data from our RDS database and send it to a shared redshift instance. Redshift instance is used by the mode analytics tool to extract some data and run some reports for the concerned people.
<br>Question is : should I be writing a new microservice just for this job ? We don't want this to be a part of our application anymore because this task is kind of heavy and irrelevant to the actual application. But if I write a service for this it will be sitting idle when cron job is not running and wasting resources. Is lambda better for this ?
答案1
得分: 0
如果您托管在AWS上,将其在无服务器环境中以[定时]作业运行绝对是一个更好的选择。这将显著降低您的AWS费用,为您的公司节省资金。如果您只需转储这些报告,使用S3。如果您需要密集的IOPS和/或在多个可用区之间需要可用性,则使用EFS。(https://docs.aws.amazon.com/lambda/latest/dg/services-cloudwatchevents-expressions.html)。
只需创建Lambda函数,并使用CloudWatch 每小时进行调度。
如果您托管Kubernetes,还可以创建CronJob。
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: hello
spec:
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: hello
image: busybox
args:
- /bin/sh
- -c
- date; echo 从Kubernetes集群打招呼
restartPolicy: OnFailure
来源:k8s文档
英文:
If you are hosted on AWS, it's definitely a better alternative to run it in the serverless environment with [scheduled] job. This will significantly reduce your AWS bill and save your company money. If you need to just dump those reports, use S3. In case you need intensive IOPS and/or availability among multiple availability zones then use EFS. (https://docs.aws.amazon.com/lambda/latest/dg/services-cloudwatchevents-expressions.html).
Just create the lambda and schedule it with CloudWatch every hour.
If you host Kubernetes, you can also create CronJob.
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: hello
spec:
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: hello
image: busybox
args:
- /bin/sh
- -c
- date; echo Hello from the Kubernetes cluster
restartPolicy: OnFailure
Source: k8s docs
专注分享java语言的经验与见解,让所有开发者获益!
评论