Monitoring REST API status

5

I am learning and trying to resolve a case of a POST request where a large body is being sent to be processed by the API and return is a job ID to access the result.

It turns out that the time the API takes to process can vary depending on the body size and I have to check the status of the job with another GET request using the job ID to know your status. If the status is complete then I can download the result ficheiro.zip via for example URLlib.retrieve() or something similar.

What would be the best way to monitor the various POST requests sent to know if your status is complete and if so download.

I'm looking for a standard, good practice, or even some import module that helps.

    
asked by anonymous 22.12.2014 / 14:06

1 answer

4

I do not know that there is any standard solution for this kind of problem. I can simply suggest using polling, type:

import threading
import thread
jobs = set()

def iniciar_job(dados):
    global jobs
    body = criar_body(dados)
    job_id = efetuar_post(body)
    jobs.append(job_id)

def download_zip(job_id):
    #use URLlib ou qualquer outro mecanismo para baixar o .zip
    pass

def checar_jobs():
    global jobs
    for job_id in list(jobs):
        if job_finalizado(job_id):
            thread.start_new_thread(download_zip, (job_id,))
            jobs.remove(job_id)

# checar jobs a cada 3 segundos
threading.Timer(3.0, checar_jobs).start()
    
23.12.2014 / 21:52