· 7 years ago · Nov 28, 2018, 08:40 AM
1def get_running_job_id(jobname):
2 access_key = "AKIAJ7SWM7OHOIWLYNKQ"
3 secret_key = "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"
4 client = get_client()
5 next_token = ""
6 print("Running Job...")
7 while next_token != None:
8 resp = None
9 if next_token == '':
10 resp = client.get_job_runs(
11 JobName=jobname
12 )
13 else:
14 resp = client.get_job_runs(
15 JobName=jobname,
16 NextToken=next_token
17 )
18 for job in resp["JobRuns"]:
19 if job["JobRunState"] == "RUNNING":
20 # this is our current job
21 logging.info(job["Id"])
22 state1 = client.get_job_run(JobName=jobname, RunId=job["Id"])
23 state=state1['JobRun']['JobRunState']
24 logging.info(state)
25 while state == 'RUNNING':
26 time.sleep(180)
27 state1 = client.get_job_run(JobName=jobname, RunId=job["Id"])
28 state = state1['JobRun']['JobRunState']
29 logging.info(state)
30 return job["Id"]
31 return state