Laravel 5日程安排不起作用 [英] Laravel 5 schedule not working
问题描述
我的laravel版本是5.0.28,我在cloud9上构建,并且将此命令添加到了我的cron中:
My laravel version is 5.0.28, I build on cloud9, and I added this command to my cron:
#!/bin/bash
PATH=/usr/bin
* * * * * php /home/ubuntu/workspace/app/artisan scheduled:run 1>> /dev/null 2>&1
我在Kernel.php
上添加了此代码.我引用了以下网站: https://laravel-news.com/2014/11 /laravel-5-scheduler/
I added this code on my Kernel.php
. I referenced this site: https://laravel-news.com/2014/11/laravel-5-scheduler/
<?php namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use App\Http\Controllers\ApiController;
class Kernel extends ConsoleKernel {
protected $commands = [
'App\Console\Commands\Inspire',
];
protected function schedule(Schedule $schedule)
{
$schedule->call('ApiController@test_job')->hourly();
}
}
我等待了一下,但仍然没有用,所以我尝试使用命令php artisan schedule:run
,然后得到:No scheduled commands are ready to run.
I waited and it still didn't work, so I tried to use the command php artisan schedule:run
, and I got: No scheduled commands are ready to run.
我搜索并找到了以下答案: Laravel 5 类别不存在";使用调度程序时
I searched and found this answer: Laravel 5 "Class does not exist" when using the scheduler
所以我修改了我的代码.另外,此代码没有指定时间,因此我修改了cron
以指定时间,但仍然无法正常工作.我没有其他想法了.请帮忙.谢谢.
So I modified my code. Also, this code had no specified time, so I modified my cron
to specify a time, but it still doesn't work. I have no more ideas. please help. Thanks.
代码
$schedule->call(join('@', [ApiController::class, 'test_job']));
cron
0 0,3,6,9,12,15,18,21 * * * php /home/ubuntu/workspace/app/artisan schedule:run 1>> /dev/null 2>&1
30 1,4,7,10,13,16,19,22 * * * php /home/ubuntu/workspace/app/artisan schedule:run 1>> /dev/null 2>&1
推荐答案
Laravel计划程序适用于命令,而不适用于控制器方法:
Laravel scheduler works with commands, not with controller methods:
- 创建命令:
php artisan make:command PurchasePodcast
- 编辑命令:
namespace App\Console\Commands;
use Illuminate\Console\Command;
class PurchasePodcast extends Command
{
protected $name = 'purchase:podcast';
public function fire()
{
// do stuff here
}
}
- 向
Console\Kernel.php
添加命令:
- add command to
Console\Kernel.php
:
protected $commands = [
'App\Console\Commands\PurchasePodcast',
];
- 在调度程序中使用命令:
$schedule->command('purchase:podcast')->hourly();
这篇关于Laravel 5日程安排不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!