[英]Laravel 5.4 Scheduler Cron not working in Cloudway server
這是我在Cloudway服務器中的cron job命令:
* * * * * php /home/1432345-6789110.cloudwaysapps.com/pedisfdfdsddd/public_html/artisan schedule:run >> /dev/null 2>&1
cron確實每分鍾運行一次,但是它不執行命令。 如果我手動鍵入php artisan命令:php artisan命令:name->即可。
以下是我的kernel.php和customCommand.php kernel.php
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
protected $commands = [
Commands\CustomCommand::class,
];
protected function schedule(Schedule $schedule)
{
$schedule->command('custom:command')->everyMinute();
}
protected function commands()
{
require base_path('routes/console.php');
}
}
customCommand.php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use DB;
class CustomCommand extends Command
{
protected $signature = 'command:name';
protected $description = 'Delete all read notifications after 3 days';
public function __construct()
{
parent::__construct();
}
public function handle()
{
DB::table('notifications')
->whereIn('type', ['App\Notifications\WeeklyReader', 'App\Notifications\WeeklyFile'])
->where([
['created_at', '<=', \Carbon\Carbon::now()->subDays(3)->toDateTimeString()],
['read_at', '!=', 'null'],
])
->delete();
$this->info('All notifications are deleted successfully!');
}
}
在方法Kernel::schedule
的定義中,您不應該使用簽名變量中定義的命令名稱嗎? 例如,代替custom:command
,它應該是:
protected function schedule(Schedule $schedule)
{
$schedule->command('command:name')->everyMinute();
}
另外,我建議您更改cron作業以將輸出轉儲到臨時文件中,而不是將其發送到/ dev / null。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.