What about:
/tasks and /tasks/{taskId} are the usual set of all tasks and a single task, respectively.
/tasksqueue are the tasks in the queue, and /tasksqueue/top is the top of the queue and only supports GET. Suppose all tasks have a unique identifier.
Then issue GET /tasksqueue/top to get the task identifier at the top of the queue, and issue DELETE /tasksqueue/{taskId} to try to jump out of the queue.
If this fails, that is, returns a non-20x, it means that someone else has jumped into the queue between your calls.
If this succeeds, it will return the task to its body, and you can do what you want with it, knowing that you successfully pulled it out. Or, since you know your identifier, you can get task information from /tasks/{taskId} .
He must not succeed more than once.
And you can issue DELETE /tasksqueue/{taskId} several times with the same overall effect on the system as one of them, so DELETE acts idempotently as it should. (The fact that all or all but the first DELETE calls return non-20x does not change this fact.)
source share