|
1 | 1 | # pylint: disable=import-error
|
2 |
| -import os |
| 2 | +from diracx.client import Dirac |
| 3 | +from diracx.client.models import JobSearchParams |
3 | 4 |
|
4 |
| -if os.getenv("DIRAC_ENABLE_DIRACX_JOB_MONITORING", "No").lower() in ("yes", "true"): |
5 |
| - from diracx.client import Dirac |
6 |
| - from diracx.client.models import JobSearchParams |
| 5 | +from diracx.cli.utils import get_auth_headers |
| 6 | +from diracx.core.preferences import DiracxPreferences |
7 | 7 |
|
8 |
| - from diracx.cli.utils import get_auth_headers |
9 |
| - from diracx.core.preferences import DiracxPreferences |
| 8 | +from DIRAC.Core.Utilities.ReturnValues import convertToReturnValue |
10 | 9 |
|
11 |
| - from DIRAC.Core.Utilities.ReturnValues import convertToReturnValue |
12 | 10 |
|
13 |
| - class JobMonitoringClient: |
14 |
| - def __init__(self, *args, **kwargs): |
15 |
| - self.endpoint = DiracxPreferences().url |
| 11 | +class JobMonitoringClient: |
| 12 | + def __init__(self, *args, **kwargs): |
| 13 | + self.endpoint = DiracxPreferences().url |
16 | 14 |
|
17 |
| - def fetch(self, parameters, jobIDs): |
18 |
| - with Dirac(endpoint=self.endpoint) as api: |
19 |
| - jobs = api.jobs.search( |
20 |
| - parameters=["JobID"] + parameters, |
21 |
| - search=[{"parameter": "JobID", "operator": "in", "values": jobIDs}], |
22 |
| - headers=get_auth_headers(), |
23 |
| - ) |
24 |
| - return {j["JobID"]: {param: j[param] for param in parameters} for j in jobs} |
| 15 | + def fetch(self, parameters, jobIDs): |
| 16 | + with Dirac(endpoint=self.endpoint) as api: |
| 17 | + jobs = api.jobs.search( |
| 18 | + parameters=["JobID"] + parameters, |
| 19 | + search=[{"parameter": "JobID", "operator": "in", "values": jobIDs}], |
| 20 | + headers=get_auth_headers(), |
| 21 | + ) |
| 22 | + return {j["JobID"]: {param: j[param] for param in parameters} for j in jobs} |
25 | 23 |
|
26 |
| - @convertToReturnValue |
27 |
| - def getJobsMinorStatus(self, jobIDs): |
28 |
| - return self.fetch(["MinorStatus"], jobIDs) |
| 24 | + @convertToReturnValue |
| 25 | + def getJobsMinorStatus(self, jobIDs): |
| 26 | + return self.fetch(["MinorStatus"], jobIDs) |
29 | 27 |
|
30 |
| - @convertToReturnValue |
31 |
| - def getJobsStates(self, jobIDs): |
32 |
| - return self.fetch(["Status", "MinorStatus", "ApplicationStatus"], jobIDs) |
| 28 | + @convertToReturnValue |
| 29 | + def getJobsStates(self, jobIDs): |
| 30 | + return self.fetch(["Status", "MinorStatus", "ApplicationStatus"], jobIDs) |
33 | 31 |
|
34 |
| - @convertToReturnValue |
35 |
| - def getJobsSites(self, jobIDs): |
36 |
| - return self.fetch(["Site"], jobIDs) |
| 32 | + @convertToReturnValue |
| 33 | + def getJobsSites(self, jobIDs): |
| 34 | + return self.fetch(["Site"], jobIDs) |
0 commit comments