Skip to content

Instantly share code, notes, and snippets.

@tiberiuichim
Created August 15, 2017 07:34
Show Gist options
  • Save tiberiuichim/3321aabf2b03b6c706b91e958bcc2438 to your computer and use it in GitHub Desktop.
Save tiberiuichim/3321aabf2b03b6c706b91e958bcc2438 to your computer and use it in GitHub Desktop.
def get_job_finish_status(phash_id, timeout=100):
""" Wait for the job to finish or abort if job is unable to finish
Job status can be one of:
- QUEUED
- STARTED
- DEFERRED
- FINISHED
- FAILED
If the job fails to move from queued, deferred to other states, we will
timeout (return False) after the given timeout period.
"""
cycle = 0
os = ''
while True:
job = get_assigned_job(phash_id)
if job is None:
return False
st = job.get_status()
if st != os:
cycle = 0
os = st
if st == JS.FINISHED: # TODO: should we check cache paths?
return True
if st == JS.FAILED:
return False
if st == JS.STARTED:
cycle = 0
time.sleep(timeout) # sleep 10 seconds
cycle += 10
if cycle >= timeout:
break
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment