【问题标题】:Is it possible to query a running Spring Batch application in order to check Jobs status?是否可以查询正在运行的 Spring Batch 应用程序以检查作业状态?
【发布时间】:2021-12-31 21:43:59
【问题描述】:

我正在开发一个 Spring Batch 应用程序。我将此应用程序部署在生产 Linux 服务器上作为我作为普通 jar 应用程序运行的 jar 文件。我的 Spring Batch 应用程序已启动并运行,事实上我的 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);
    }
    
}

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

【问题讨论】:

  • 这就是数据库表的用途。

标签: java spring-boot spring-batch spring-batch-job-monitoring


【解决方案1】:

是的,您可以使用 Spring Batch 数据库表来检查这里的文档:https://docs.spring.io/spring-batch/docs/current/reference/html/schema-appendix.html

【讨论】:

    猜你喜欢
    • 2021-12-10
    • 2019-02-16
    • 2014-08-25
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 2020-09-17
    • 1970-01-01
    相关资源
    最近更新 更多