Search code examples
phppriority-queuelaravel-5.1

How to execute a job immediately using Laravel Queue


I have a sign up form which sends an email notification to the user email and I used Laravel Queue for all my background process (e.g. Mail::queue...).

My question is, say I have a 20 queued jobs in my table. And I always want to prioritize all email invitations first, I don't want it to wait. Is this possible? I still want to use the queue principle though.


Solution

  • You could setup multiple queues. For example one for background jobs with low priorities and one for email with a high priority.

    See this link from the Laravel documentation regarding assign jobs to specific queues. Pushing Jobs Onto The Queue. Look into 'Specifying The Queue For A Job'.

    After you have done setting this up you can assigning priorities to the queues. See the following link to the Laravel documentation. Running The Queue Listener. Look into 'Queue Priorities'.

    Quote from Laravel documentation:

    In this example, jobs on the high queue will always be processed before moving onto jobs from the low queue.