简体   繁体   中英

Run laravel jobs one time at specific time only

I came across a situation i want to trigger some code at specific time, ie when user does booking, the freelancer must accept/reject the booking request, if he doesnt, after x duration (15* mins lets say) it would be rejected and user would get push notification. All code is done but currently im running a cronjob after each 1 minute which checks for any unresponded bookings and checks when their time (15mins, dynamic) passed so then I execute my code for afterward, it is not good i guess as its running db queuries over and over each minute.

I'm aware with laravel queue jobs as well but didnt see anything for me to run that job for a specific time only (ie execute this job after 15mins, if it isnt responded, reject it)

have you looked at Queue delay?

https://laravel.com/docs/9.x/queues#delayed-dispatching

This sounds like what you are looking for, I would just trigger the queue and delay when they make a booking so it executes 15 minutes after.

Use scheduled tasks.

use App\Console\Commands\SendEmailsCommand;
 
$schedule->command('emails:send Taylor --force')->daily();
 
$schedule->command(SendEmailsCommand::class, ['Taylor', '--force'])->daily();

https://laravel.com/docs/9.x/scheduling#scheduling-artisan-commands

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM