sunxia
2022-04-18 7290aa76586b4222c121ddbaea3e1f18202a6e85
FNM603batch重复执行调整

FNM603batch重复执行调整上线
2个文件已修改
21 ■■■■■ 已修改文件
force-app/main/default/classes/AgencyShareUpdateBatch.cls 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/NFM603Batch.cls 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/AgencyShareUpdateBatch.cls
@@ -30,6 +30,16 @@
    }
    global void finish(Database.BatchableContext bc) {
        // 如果前一个603的batch正在等待状态,则取消掉前一个batch的执行
        List<AsyncApexJob> lstJobs = [SELECT Id FROM AsyncApexJob WHERE (Status = 'Queued' OR Status = 'Holding') AND ApexClass.Name = 'NFM603Batch'];
        for (AsyncApexJob job : lstJobs) {
            try {
                System.abortJob(job.Id);
            } catch(Exception ex ) {
                System.debug(ex);
            }
        }
        Id execBTId = Database.executebatch(new NFM603Batch(),1);
    }
}
force-app/main/default/classes/NFM603Batch.cls
@@ -9,6 +9,17 @@
    global Database.QueryLocator start(Database.BatchableContext bc) {
        // 如果前一个603的batch正在执行,则后一个等待5s再执行
        List<AsyncApexJob> lstJobs = [SELECT Id FROM AsyncApexJob WHERE Id !=: bc.getJobId() AND (Status = 'Preparing' OR Status = 'Processing') AND ApexClass.Name = 'NFM603Batch'];
        if (lstJobs != null && lstJobs.size() > 0) {
            Long startTime = DateTime.now().getTime();
            Long finishTime = DateTime.now().getTime();
            while ((finishTime - startTime) < 5000) {
                //sleep for 5s
                finishTime = DateTime.now().getTime();
            }
        }
        if (this.repairIdList != null) {
            return Database.getQueryLocator([SELECT Id,AwaitToSendAWS__c FROM Repair__c WHERE Id IN:repairIdList]);
        }