librelist archives

« back to archive

create a new job per HTTP request

create a new job per HTTP request

From:
sam pendleton
Date:
2014-12-30 @ 20:27
given i have an app running somewhere and someone sends a request for a resource

if it's a request for a page, maybe that page should be cached by the
web server and served

but what if it's something like a POST request

does it make sense for an app to create a new job for each http POST
request on a certain endpoint or should the endpoint process the
request immediately?

by immediately, i mean use a few function calls to validate the data,
insert the data, and on success or failure of updating the db, return
this status to the user

i can do this with 3-4 lines, but i can't decide if i should just
throw the request into a job scheduler

Re: [flask] create a new job per HTTP request

From:
Daniel Neuhäuser
Date:
2014-12-30 @ 21:54
> does it make sense for an app to create a new job for each http POST
> request on a certain endpoint or should the endpoint process the
> request immediately?
No, it does not make sense at all to create new jobs for each HTTP post 
request. You should always process the request immediately.

> by immediately, i mean use a few function calls to validate the data,
> insert the data, and on success or failure of updating the db, return
> this status to the user
Which is btw, exactly what happens in the tutorial.

> i can do this with 3-4 lines, but i can't decide if i should just
> throw the request into a job scheduler
You should never throw requests in a job scheduler.

One caveat to what I said: Sometimes you will find that you simply cannot 
perform a computation fast enough to respond to a request in any 
acceptable timeframe with a final result. In that case you should still 
respond immediately but process asynchronously in a matter that allows you
to check on the progress/state of the process and retrieve the result once
it has been computed. This is however the exception and not the rule.