laravel中的一次自定义cron计划 [英] One time custom cron schedule in laravel
问题描述
我想在自定义日期仅运行一次cron&用户在表格中输入的时间.最好的方法是什么?
I want to run a cron just once at a custom date & time entered by the user in a form. What is the best way to do this?
我发现可以像这样在laravel中安排自定义cron
I found that a custom cron can be scheduled in laravel like this
->cron(‘* * * * * *’);
按照自定义Cron时间表运行任务.
Run the task on a custom Cron schedule.
但是我找不到*表示的时间格式.
But I could not find the time format what the * mean.
或更简单的是,可以通过添加日期和时间来做到这一点.
Or much simpler, can it be done like this by adding the date and time.
->at('28/04/2020 13:00');
这怎么办?
推荐答案
Laravel文档在此处任务计划
Laravel documentation has in detail description on that in here Task Scheduling
您可以将调度逻辑添加到给定文件中
You can add your scheduling logic in a given file
App \ Console \ Kernel
App\Console\Kernel
当前,laravel具有与您的要求完全匹配的功能,但它提供了-> monthlyOn(23,'13:00');
,通过它您可以满足您的要求,它每月23日的13:00运行任务
Currently, laravel have the kind of functionality that exactly match your requirement but it provide a ->monthlyOn(23, '13:00');
via which you can achieve your requirement, It Run the task every month on the 23th at 13:00
protected function schedule(Schedule $schedule)
{
$schedule->call(function () {
})->->monthlyOn(23, '13:00');
}
上面的代码每个月23日(服务器时间13:00)运行任务.
The above code runs the task every month on the 23th at 13:00 hours server time.
出于您的目的,您可以按照以下说明更改cron计划
For your purpose you can change cron scheduling as given below
00 13 28 APR Fri *
1st * Minute
2nd * Hour
3rd * Day of the Month
4th * Month of the Year
5th * Day of the Week
6th * Year
这篇关于laravel中的一次自定义cron计划的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!