Select to view content in your preferred language

JobManager AttributeError

389
1
a week ago
tcrammond
Occasional Contributor

I'm attempting to look at the jobs for a GPService, but I get the following Attribute Error. I guess my question is "am I doing this right?" - I have a GPService that is an arcgis.gis.server.admin._services.Service, from which I get the JobManager, and from that, I thought, the jobs...

 

Maybe a more general way to frame the question is "how do I get all the jobs for a given GPService?"

 

Error:

jobs = service.jobs.search()

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[28], line 1
----> 1 jobs = service.jobs.search()

File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\server\admin\_services.py:2123, in JobManager.search(self, start_time, end_time, status, username, machine)
   2119 results = []
   2120 res = self._con.get(url, params)
   2121 results = [
   2122     Job(url="%s/%s" % (self._url, key), con=self._con)
-> 2123     for key in res["results"].keys()
   2124 ]
   2125 while res["nextStart"] > -1:
   2126     params["start"] = res["nextStart"]

AttributeError: 'list' object has no attribute 'keys'

 

0 Kudos
1 Reply
VenkataKondepati
Occasional Contributor

The error is from a Python API/server mismatch, not your idea. Two things to check, then two working patterns.

Check first

  1. The GP service must be asynchronous (executionType = esriExecutionTypeAsynchronous). Synchronous tasks have no jobs.

  2. Your ArcGIS API for Python in Pro is older than your Server (11.x). Newer Server returns a list for results, but the older client expects a dict → your AttributeError.

Fix options

A) Use the supported Admin path (works when versions mismatch):

from arcgis.gis import GIS

gis = GIS("https://yourportal/portal", "admin", "pwd")
srv  = gis.admin.servers.list()[0]                       # pick the hosting/server
svc  = srv.services.get("Folder/MyGPService.GPServer")   # or just "MyGPService.GPServer"

# hit the /jobs endpoint directly
resp = svc._con.get(f"{svc._url}/jobs", params={"f":"json"})   # add filters: status, startTime, endTime
jobs = resp.get("jobs", [])
print(len(jobs), jobs[:3])

B) Update the client, then use the high-level helper:

  • In Pro’s Python Package Manager, update to the latest arcgis package.

  • Then:

jobs = svc.jobs.search(status="esriJobSucceeded")  # should now work

Notes

  • If your service has multiple tasks, you can also query per task:
    .../GPServer/<TaskName>/jobs?f=json

  • For federated sites, use the Server Admin URL (…/arcgis/admin/services/…/jobs) when you need full history.

0 Kudos