限制批处理作业的生命周期 [英] Limit the lifetime of a batch job

查看:104
本文介绍了限制批处理作业的生命周期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以将正在运行的弹簧批处理作业的寿命限制为例如23小时?

Is there a way to limit the lifetime of a running spring-batch job to e.g. 23 hours?

我们每天通过cron作业开始一个批处理作业,他的作业大约需要9个小时.在某些情况下,数据库连接太慢,以至于该工作需要60多个小时才能完成.问题是下一个工作实例在第二天由cronjob启动,然后在第二天又由另一个人启动,然后又由另一个人启动.

We start a batch job daily by a cron job and he job takes about 9 hours. It happened under some circumstances that the DB connection was so slow that the job took over 60 hours to complete. The problem is that the next job instance gets started by the cronjob the next day - and then anotherone the day after - and anotherone...

如果此作业未在例如以下时间内完成23小时后,我想终止它并返回错误.有没有一种方法可以立即使用spring-batch来完成?

If this job is not finished within e.g. 23 hours, I want to terminate it and return an error. Is there a way to do that out-of-the-box with spring-batch?

推荐答案

Spring Batch专门避免了工作编排的问题.话虽如此,您可以在您的工作中添加一个侦听器,以检查其他实例是否正在运行,并在启动该实例之前对其停止调用.不知道每项工作是做什么的,我不确定那将是多么有效,但这应该是一个开始.

Spring Batch specifically avoids the issue of job orchestration which this falls into. That being said, you could add a listener to your job that checks for other instances running and calls stop on them before beginning that one. Not knowing what each job does, I'm not sure how effective that would be, but it should be a start.

这篇关于限制批处理作业的生命周期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆