From 7290aa76586b4222c121ddbaea3e1f18202a6e85 Mon Sep 17 00:00:00 2001
From: sunxia <sunxia@prec-tech.com>
Date: 星期一, 18 四月 2022 14:53:02 +0800
Subject: [PATCH] FNM603batch重复执行调整

---
 force-app/main/default/classes/NFM603Batch.cls            |   11 +++++++++++
 force-app/main/default/classes/AgencyShareUpdateBatch.cls |   10 ++++++++++
 2 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/force-app/main/default/classes/AgencyShareUpdateBatch.cls b/force-app/main/default/classes/AgencyShareUpdateBatch.cls
index 18d332d..6e21085 100644
--- a/force-app/main/default/classes/AgencyShareUpdateBatch.cls
+++ b/force-app/main/default/classes/AgencyShareUpdateBatch.cls
@@ -30,6 +30,16 @@
     }
 
     global void finish(Database.BatchableContext bc) {
+
+        // 濡傛灉鍓嶄竴涓�603鐨刡atch姝e湪绛夊緟鐘舵�侊紝鍒欏彇娑堟帀鍓嶄竴涓猙atch鐨勬墽琛�
+        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);
     }
 }
\ No newline at end of file
diff --git a/force-app/main/default/classes/NFM603Batch.cls b/force-app/main/default/classes/NFM603Batch.cls
index 2da7f20..15dface 100644
--- a/force-app/main/default/classes/NFM603Batch.cls
+++ b/force-app/main/default/classes/NFM603Batch.cls
@@ -9,6 +9,17 @@
 
     global Database.QueryLocator start(Database.BatchableContext bc) {
 
+        // 濡傛灉鍓嶄竴涓�603鐨刡atch姝e湪鎵ц锛屽垯鍚庝竴涓瓑寰�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]);
         }

--
Gitblit v1.9.1