|
20 | 20 | from DIRAC.Core.Utilities.ClassAd.ClassAdLight import ClassAd |
21 | 21 | from DIRAC.Core.Utilities.Decorators import deprecated |
22 | 22 | from DIRAC.Core.Utilities.DErrno import EWMSJMAN, EWMSSUBM, cmpError |
23 | | -from DIRAC.Core.Utilities.ReturnValues import S_ERROR, S_OK, convertToReturnValue, returnValueOrRaise, SErrorException |
| 23 | +from DIRAC.Core.Utilities.ReturnValues import S_ERROR, S_OK, SErrorException, convertToReturnValue, returnValueOrRaise |
24 | 24 | from DIRAC.FrameworkSystem.Client.Logger import contextLogger |
25 | 25 | from DIRAC.ResourceStatusSystem.Client.SiteStatus import SiteStatus |
26 | 26 | from DIRAC.WorkloadManagementSystem.Client import JobMinorStatus, JobStatus |
@@ -1510,14 +1510,53 @@ def setJobCommandStatus(self, jobID, command, status): |
1510 | 1510 | return self._update(f"UPDATE JobCommands SET Status={status} WHERE JobID={jobID} AND Command={command}") |
1511 | 1511 |
|
1512 | 1512 | ##################################################################################### |
| 1513 | + def fillJobsHistorySummary(self): |
| 1514 | + """Fill the JobsHistorySummary table with the summary of the jobs in a final state""" |
| 1515 | + |
| 1516 | + defString = "Status, Site, Owner, OwnerGroup, JobGroup, JobType, ApplicationStatus, MinorStatus" |
| 1517 | + valuesString = "COUNT(JobID), SUM(RescheduleCounter)" |
| 1518 | + final_states = "', '".join(JobStatus.JOB_FINAL_STATES + JobStatus.JOB_REALLY_FINAL_STATES) |
| 1519 | + final_states = f"'{final_states}'" |
| 1520 | + |
| 1521 | + query = ( |
| 1522 | + f"INSERT INTO JobsHistorySummary SELECT {defString}, {valuesString} " |
| 1523 | + f"FROM Jobs WHERE Status IN ({final_states}) AND LastUpdateTime < UTC_DATE() " |
| 1524 | + f"GROUP BY {defString}" |
| 1525 | + ) |
| 1526 | + result = self._update(query) |
| 1527 | + if not result["OK"]: |
| 1528 | + return result |
| 1529 | + return S_OK(result["Value"]) |
| 1530 | + |
1513 | 1531 | def getSummarySnapshot(self, requestedFields=False): |
1514 | 1532 | """Get the summary snapshot for a given combination""" |
1515 | 1533 | if not requestedFields: |
1516 | 1534 | requestedFields = ["Status", "MinorStatus", "Site", "Owner", "OwnerGroup", "JobGroup"] |
1517 | 1535 | valueFields = ["COUNT(JobID)", "SUM(RescheduleCounter)"] |
1518 | 1536 | defString = ", ".join(requestedFields) |
1519 | 1537 | valueString = ", ".join(valueFields) |
1520 | | - result = self._query(f"SELECT {defString}, {valueString} FROM Jobs GROUP BY {defString}") |
| 1538 | + final_states = "', '".join(JobStatus.JOB_FINAL_STATES + JobStatus.JOB_REALLY_FINAL_STATES) |
| 1539 | + final_states = f"'{final_states}'" |
| 1540 | + |
| 1541 | + query = f"SELECT {defString}, {valueString} FROM (" |
| 1542 | + # All jobs that are NOT in a final state |
| 1543 | + query += ( |
| 1544 | + f"SELECT {defString}, {valueString}, COUNT(JobID), SUM(RescheduleCounter) " |
| 1545 | + f"FROM Jobs WHERE STATUS NOT IN ({final_states}) " |
| 1546 | + f"GROUP BY {defString}, {valueString} " |
| 1547 | + ) |
| 1548 | + query += "UNION ALL " |
| 1549 | + # Recent jobs only (today) that are in a final state |
| 1550 | + query += ( |
| 1551 | + f"SELECT {defString}, {valueString}, COUNT(JobID), SUM(RescheduleCounter) " |
| 1552 | + f"FROM Jobs WHERE Status IN ({final_states}) AND LastUpdateTime >= UTC_DATE() " |
| 1553 | + f"GROUP BY {defString}, {valueString} " |
| 1554 | + ) |
| 1555 | + query += "UNION ALL " |
| 1556 | + # Cached history (of jobs in a final state) |
| 1557 | + query += f"SELECT * FROM JobsHistorySummary) AS combined GROUP BY {defString}, {valueString}" |
| 1558 | + |
| 1559 | + result = self._query(query) |
1521 | 1560 | if not result["OK"]: |
1522 | 1561 | return result |
1523 | 1562 | return S_OK(((requestedFields + valueFields), result["Value"])) |
|
0 commit comments