Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dev.jim's avatar

Multiple jobs and queue

I am confused by the job and queue. And have hard time to use them in my application.

Basically, I need to send reminder to users when their tasks are due daily. There are many tasks in the database table, query them will takes a lot of time. Hence I would like the process run in background. Upon checking the tasks due date, it will send a notification to the users.

What I come in mind is, separated the db query and send notification process by different time. Eg, in midnight 1am , I will schedule to run the collecting data first (query database and get necessary data). And then in the morning send the notification according the due tasks found in 1am.

How can I do it?

Do I need to do 2 cron jobs to do the process? 1 for collect data (querying db) and 1 for send notification? But according to documentation, all I need is create one cron job and using scheduler to schedule the process. This I not understand how can I do it. Also In the document, it has mentioned Job Chaining method, from what I understanding, it only order the jobs priority. It can't be run the job by specific time.

Also, if i create a job of collecting data, does it run in the background?

0 likes
5 replies
sr57's avatar

all I need is create one cron job

Yes, at the end of the doc

https://laravel.com/docs/9.x/scheduling#running-the-scheduler

using scheduler to schedule the process

Define the processes schedules by configruring the scheduler

https://laravel.com/docs/9.x/scheduling#defining-schedules

Job Chaining method, from what I understanding, it only order the jobs priority

Not the priority, just running jobs in a row.

if i create a job of collecting data, does it run in the background

Yes

dev.jim's avatar

@sr57 thanks. This is what I came up with after digger deeper into the issue.

  1. Create a command and scheduler it to run on midnight.
  2. Create a Send Reminder job.
  3. In the command handler, will dispatch the the Send Reminder job upon the data collected from db.
  4. In dispatching the send email job add a delay method with calculate the time that it should be executed, refer from the time it dispatched.

I am using delay method because It seems jobs did not come with set specific time feature. Am I right?

And about delay, I can have same fixed time?

For example,

#assigning job in command handler
foreach($data as $details) :
    dispatch(new SendEmail($details))->delay( getdelayedtime() ); 
endforeach;
 #function to get time difference 
function getdelayedtime(){
      $now = Carbon::now();
       $upcoming = = new Carbon();
        $end = $upcoming->hour = 8; //make it run at 8:00am
        return $start->diffInSeconds($end); 
 }

Will the job overlapped? Since the time difference are all set to coming 8am.

Please or to participate in this conversation.