簡體   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