stdclass
stdclass

Reputation: 3632

Pause Queue in a Job

I have following problem to solve:

Multiple Users can submit Jobs to a Queue via a Web Interface. This Jobs are then stored in the Database via the database Queue Driver.

Now my problem is: I want the Queue to run all Jobs until inside a job I say something like $queue->pause() because for the next Job to run I need some confirmation from the User.

How would I do something like this?

My current "solution" which didn't work was this: create 2 different job types:

The queue worked all ImageProcessingJobs until it hit a UserNotificationJob. Inside the UserNotificationJob->handle() I called Artisan::call("queue:restart"); which stopped the Queue. The problem with this solution is: The UserNotificationJob also got deleted. So if I would start the Queue again the Queue would immediately start with the remainig ImageProcessingJobs without waiting for the actual confirmation.

I'm also open to other architectural solutions without a Queue system.

Upvotes: 2

Views: 842

Answers (1)

the4thamigo_uk
the4thamigo_uk

Reputation: 875

One approach which avoids pausing the queue, is to have the UserNotificationJob wait on a SyncEvent (the SyncEvent is set when then confirmation comes back from the user). You can have this wait timing-out if you like, but then you need to repost the job to the queue. If you decide to timeout and repost, you can use job chaining to setup dependencies between jobs so that nothing can be run until the UserNotificationJob competes.

Another approach might be to simply avoid posting the remaining jobs until the confirmation is sent from the user.

Upvotes: 1

Related Questions