简体   繁体   English

仅在特定时间运行一次 laravel 作业

[英]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.我遇到了一种情况,我想在特定时间触发一些代码,即当用户进行预订时,自由职业者必须接受/拒绝预订请求,如果他不接受,则在 x 持续时间(15 * 分钟)后它将被拒绝并且用户会收到推送通知。 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.所有代码都已完成,但目前我每 1 分钟运行一次 cronjob,检查任何未响应的预订并检查他们的时间(15 分钟,动态)何时过去,然后我执行我的代码,我猜它运行的数据库不好每分钟一遍又一遍的查询。

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)我也知道 laravel 队列作业,但没有看到任何东西让我只在特定时间内运行该作业(即在 15 分钟后执行该作业,如果它没有响应,则拒绝它)

have you looked at Queue delay?你看过队列延迟吗?

https://laravel.com/docs/9.x/queues#delayed-dispatching 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.这听起来像您正在寻找的东西,我会在他们进行预订时触发队列并延迟,以便在 15 分钟后执行。

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 https://laravel.com/docs/9.x/scheduling#scheduling-artisan-commands

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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