Tuesday, March 21, 2017

Starting the Laravel cron job on a Mac

I have a command scheduled in the Laravel 5.4 scheduler and would like to start the Laravel cron on Mac OS X El Capitan.

app/Console/Kernel.php

<?php
namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    protected $commands = [
        'App\Console\Commands\GetToken'
    ];

    protected function schedule(Schedule $schedule) {
        $schedule->command('gettoken')->everyMinute();
    }

    protected function commands() {
        require base_path('routes/console.php');
    }
}

My GetToken.php makes an API call and then a DB change. I believe that this is working properly, as I can run the task directly from the cli using:

php /path/to/project/artisan schedule:run 1>> /dev/null 2>&1

To edit my cron file I use:

env EDITOR=nano crontab -e

I then add:

* * * * * php /path/to/project/artisan schedule:run >> /dev/null 2>&1

I save with ctrl+o and exit with ctrl+x.

Re-editing the file shows that the changes have saved.

Running crontab -l shows the text that I entered into the crontab file.

My cron never runs. I can only get it to run once by running manually using the command I mentioned above.



via codee.io

Advertisement