I'm currently trying to create a web service with a RESTful API that handles some lengthy tasks (tasks).
The idea is that the user submits the task by performing a POST that returns some URL to check the status of the job, which also contains the URL for the results. After the task is completed (i.e., some value was written to the database), the results URL will return the corresponding information (instead of any results), and the task URL will indicate the completed status.
Unfortunately, the calculations are quite intense, so you can run it only once, so jobs must be queued.
In pseudo something like this is needed
(def job-queue (atom queue)) ;; some queue (def jobs (atom {})) (defn schedule-job [params] ;; schedules the job into the queue and ;; adds the job to a jobs map for checking status via GET ;; note that the job should not be evaluated until popped from the queue ) (POST "/analyze" [{params :params}] (schedulde-job params)) (GET "job/:id" [:d] (get @jobs id)) ;; Some function that pops the next item from the queue ;; and evaluates it when the previous item is complete ;; Note: should not terminate when queue is empty!
I looked at Lamina , which allows asynchronous processing, but this does not seem to fit my needs.
My question is how to delete the queue of job queues and complete the task after the previous one is completed, without interruption when the queue is empty, i.e. constantly process incoming tasks.
Joelkuiper
source share