I've built a system based on Laravel where users are able to begin a "task" which repeats a number of times, with a delay between each repetition. I've accomplished this by queueing a job with an amount
argument, which then recursively queues an additional job until the count is up.
For example, I start my task with 3 repetitions:
- A job is queued with an
amount
argument of 3. It is ran, the amount is decremented to 2. The same job is queued again with a delay of 5 seconds specified. - When the job runs again, the process repeats with an
amount
of 1. - The last job executes, and now that the
amount
has reached 0, it is not queued again and the tasks have been completed.
This is working as expected, but I need to know whether a user currently has any tasks being processed. I need to be able to do the following:
- Check if a particular queue has any jobs started by a particular user.
- Check the value that was set for
amount
on that job.
I'm using the database
driver for a queue named tasks
. Is there any existing method to accomplish my goals here?
Thanks!
tasks
table, which stores the remaining count and a reference to the user. Then, on the queued job, I passed thetask_id
in. That job runs on repea and checks thetasks
table. If it doesn't find the task record it's looking for, it stops re-queueing. So instead of checking if a user has a queued job, I check thetasks
table. It isn't perfect but it's close enough for the time being. Happy to explain in more detail. – Tyler