in cli/src/klio_cli/commands/job/stop.py [0:0]
def _watch_job_state(self, job, timeout=600):
timeout = datetime.datetime.now() + datetime.timedelta(seconds=timeout)
request = (
self._client.projects()
.locations()
.jobs()
.get(
jobId=job["id"],
projectId=job["projectId"],
location=job["location"],
)
)
while datetime.datetime.now() < timeout:
try:
resp = request.execute()
except Exception as e:
msg = (
"Failed to get current status for job '{}'. Error: {}.\n"
"Trying again after 5s...".format(job["name"], e)
)
logging.info(msg)
time.sleep(5)
continue
if resp["currentState"] in JOB_STATE_MAP.values():
return
else:
msg = "Waiting for job '{}' to reach terminal state...".format(
job["name"]
)
logging.info(msg)
time.sleep(5)
msg = "Job '{}' did not reach terminal state after '{}' secs.".format(
job["name"], timeout
)
logging.error(msg)
raise SystemExit(1)