@@ -31,8 +31,8 @@ class StatesAccountingAgent(AgentModule):
3131 __summaryKeyFieldsMapping = [
3232 "Status" ,
3333 "Site" ,
34- "User " ,
35- "UserGroup " ,
34+ "Owner " ,
35+ "OwnerGroup " ,
3636 "JobGroup" ,
3737 "VO" ,
3838 "JobType" ,
@@ -41,7 +41,7 @@ class StatesAccountingAgent(AgentModule):
4141 ]
4242 __summaryDefinedFields = [("ApplicationStatus" , "unset" ), ("MinorStatus" , "unset" )]
4343 __summaryValueFieldsMapping = ["Jobs" , "Reschedules" ]
44- __renameFieldsMapping = {"JobType" : "JobSplitType" }
44+ __renameFieldsMapping = {"Owner" : "User" , "OwnerGroup" : "UserGroup" , " JobType" : "JobSplitType" }
4545
4646 # PilotsHistory fields
4747 __pilotsMapping = ["GridSite" , "ComputingElement" , "GridType" , "Status" , "VO" , "NumOfPilots" ]
@@ -95,7 +95,7 @@ def execute(self):
9595 f"{ result ['Message' ]} : won't commit PilotsHistory at this cycle" ,
9696 )
9797
98- values = result ["Value" ][ 1 ]
98+ values = result ["Value" ]
9999 for record in values :
100100 rD = {}
101101 for iP , _ in enumerate (self .__pilotsMapping ):
@@ -111,21 +111,21 @@ def execute(self):
111111
112112 # WMSHistory to Monitoring or Accounting
113113 self .log .info (f"Committing WMSHistory to { 'and ' .join (self .jobMonitoringOption )} backend" )
114- result = JobDB ()._query ("SELECT * FROM JobsHistorySummary" )
114+ result = JobDB ()._query (
115+ f"SELECT { self .__summaryKeyFieldsMapping } FROM JobsHistorySummary ORDER BY { ',' .join (self .__summaryKeyFieldsMapping )} "
116+ )
115117 if not result ["OK" ]:
116118 self .log .error ("Can't get the JobDB summary" , f"{ result ['Message' ]} : won't commit WMSHistory at this cycle" )
117119 return S_ERROR ()
118120
119- values = result ["Value" ][1 ]
120-
121+ values = result ["Value" ]
121122 now = datetime .datetime .utcnow ()
122123 self .log .info ("Start sending WMSHistory records" )
123124 for record in values :
124125 rD = {}
125126 for fV in self .__summaryDefinedFields :
126127 rD [fV [0 ]] = fV [1 ]
127- for iP , _ in enumerate (self .__summaryKeyFieldsMapping ):
128- fieldName = self .__summaryKeyFieldsMapping [iP ]
128+ for iP , fieldName in enumerate (self .__summaryKeyFieldsMapping ):
129129 rD [self .__renameFieldsMapping .get (fieldName , fieldName )] = record [iP ]
130130 record = record [len (self .__summaryKeyFieldsMapping ) :]
131131 for iP , _ in enumerate (self .__summaryValueFieldsMapping ):
0 commit comments