Monitoring REST API status

Asked

Viewed 236 times

5

I’m learning and trying to solve a POST case request where a dispatch of a body well wide to be processed by API and the return is a job ID to access the result.

It turns out that the time it takes the API to process may vary depending on the size of the body and I have to check the status of 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 route for example URLlib.retrieve() or something like that.

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

Looking for pattern, good practice or even some module to import that helps.

  • your question is not very clear, but anyway: you’ve heard of celery?

  • Haven’t heard anything about Celery yet. Maybe this API type will help you see link at the end. what is intended is to periodically query the api to obtain that the job status is complete.https://developers.arcgis.com/rest/elevation/api-reference/checking-job-status.htm

  • in English: http://stackoverflow.com/questions/9034091/how-to-check-task-status-in-celery

  • Thanks Rafael, I don’t think I need so much for my case. However thanks for sharing, Celery seems to be interesting but not for my small scale.

1 answer

4


I don’t know if there is any standard solution for this type of problem. I can suggest simply using Polling, like:

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()
  • thanks for the hint of threading , my current implementation was very similar just did not make treadhing feature , I made a while loop that went through the list of Jobs to check which finished , case removed from the list and made the download. 1x+ Thanks for the hint of threading I will read more about the module for a correct implementation.

  • You can even create a specialized Thread class that you instantiate for each job and itself has its own timer to check the progress and start downloading the file. That way you wouldn’t even have to keep the John list.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.