繁体   English   中英

是否可以查询正在运行的 Spring 批处理应用程序以检查作业状态?

[英]Is it possible to query a running Spring Batch application in order to check Jobs status?

我正在开发 Spring 批处理应用程序。 我将此应用程序部署在生产 Linux 服务器上,作为我作为普通 jar 应用程序运行的 Ajar 文件。 我的 Spring 批处理应用程序已启动并正在运行,实际上我的UpdateInfoBatch-0.0.1-SNAPSHOT.jar似乎已启动并作为进程运行:

webadmin@webadmin.myserver.it [~]# ps aux | grep java
webadmin  4677  0.1  3.2 10255180 809528 ?     Sl   Nov17  12:10 java -jar UpdateInfoBatch-0.0.1-SNAPSHOT.jar
webadmin  5152  0.0  0.0 112812   980 pts/1    S+   09:58   0:00 grep --color=auto java

我的应用程序包含两个使用 CRON 表达式在特定时间安排的作业定义:

/**
 * This bean schedules and runs our Spring Batch job.
 */
@Component
@Profile("!test")
public class SpringBatchExampleJobLauncher {

    private static final Logger LOGGER = LoggerFactory.getLogger(SpringBatchExampleJobLauncher.class);

    @Autowired
    @Qualifier("launcher")
    private JobLauncher jobLauncher;
    
    @Autowired
    @Qualifier("updateNotaryDistrictsJob")
    private Job updateNotaryDistrictsJob;

    @Autowired
    @Qualifier("updateNotaryListInfoJob")
    private Job updateNotaryListInfoJob;
   
    @Scheduled(cron = "${cron.expresion.runUpdateNotaryListInfoJob}")
    public void runUpdateNotaryListInfoJob() {
        LOGGER.info("SCHEDULED run of updateNotaryListInfoJob STARTED");
        Map<String, JobParameter> confMap = new HashMap<>();
        confMap.put("time", new JobParameter(System.currentTimeMillis()));
        JobParameters jobParameters = new JobParameters(confMap);
        try {
            jobLauncher.run(updateNotaryListInfoJob, jobParameters);
        }catch (Exception ex){
            LOGGER.error(ex.getMessage());
        }
    }
    
    
    @Scheduled(cron = "${cron.expresion.runUpdateNotaryDistrictJob}")
    public void runUpdateNotaryDistrictsJob() {
        LOGGER.info("SCHEDULED run of updateNotaryDistrictsJob STARTED");
        Map<String, JobParameter> confMap = new HashMap<>();
        confMap.put("time", new JobParameter(System.currentTimeMillis()));
        JobParameters jobParameters = new JobParameters(confMap);
        try {
            jobLauncher.run(updateNotaryDistrictsJob, jobParameters);
        }catch (Exception ex){
            LOGGER.error(ex.getMessage());
        }

    }
    

    private JobParameters newExecution() {
        Map<String, JobParameter> parameters = new HashMap<>();

        JobParameter parameter = new JobParameter(new Date());
        parameters.put("currentTime", parameter);

        return new JobParameters(parameters);
    }
    
}

现在我问是否有某种方法可以与这个正在运行的应用程序进行交互,以检查在定义到这个应用程序的作业的最后执行期间是否发生了一些错误。 是否可以查询我正在运行的应用程序询问作业状态或类似的东西?

Yes, you can use Spring Batch database tables for this check the documentation here: https://docs.spring.io/spring-batch/docs/current/reference/html/schema-appendix.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM