Skip to content

Commit 2247c6f

Browse files
committed
fix (FTS3Agent): add a monitoring delay, and avoid monitorig multiple
times per loop
1 parent 76cfbef commit 2247c6f

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/DIRAC/DataManagementSystem/Agent/FTS3Agent.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
:caption: FTS3Agent options
1313
1414
"""
15+
import datetime
1516
import errno
1617
import os
1718
from urllib import parse
@@ -54,6 +55,10 @@
5455
# when running multiple agents, we rather do it in steps
5556
JOB_MONITORING_BATCH_SIZE = 20
5657

58+
# We do not monitor a job more often
59+
# than MONITORING_DELAY in minutes
60+
MONITORING_DELAY = 10
61+
5762

5863
class FTS3Agent(AgentModule):
5964
"""
@@ -299,18 +304,29 @@ def monitorJobsLoop(self):
299304
if mod:
300305
nbOfLoops += 1
301306

307+
# Not only is it pointless to monitor right after submission
308+
# but also we would end up fetching multiple time the same job otherwise
309+
# as we call getActiveJobs by batch
310+
lastMonitor = datetime.datetime.utcnow() - datetime.timedelta(minutes=MONITORING_DELAY)
311+
302312
log.debug("Getting active jobs")
303313

304314
for loopId in range(nbOfLoops):
305315
log.info("Getting next batch of jobs to monitor", f"{loopId}/{nbOfLoops}")
306316
# get jobs from DB
307-
res = self.fts3db.getActiveJobs(limit=JOB_MONITORING_BATCH_SIZE, jobAssignmentTag=self.assignmentTag)
317+
res = self.fts3db.getActiveJobs(
318+
limit=JOB_MONITORING_BATCH_SIZE, lastMonitor=lastMonitor, jobAssignmentTag=self.assignmentTag
319+
)
308320

309321
if not res["OK"]:
310322
log.error("Could not retrieve ftsJobs from the DB", res)
311323
return res
312324

313325
activeJobs = res["Value"]
326+
if not activeJobs:
327+
log.info("No more jobs to monitor")
328+
break
329+
314330
log.info("Jobs queued for monitoring", len(activeJobs))
315331

316332
# We store here the AsyncResult object on which we are going to wait

0 commit comments

Comments
 (0)