mardi 25 juillet 2017

Laravel 5.4 Scheduler Cron not working in Cloudway server

this is my cron job command in cloudway server:

          • php /home/http://ift.tt/2uwklBK schedule:run >> /dev/null 2>&1

The cron did run every minute, but it does NOT execute the command. If i type the php artisan command manually: php artisan command:name --> it work.

Below is my kernel.php and 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!');
}
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire