I don't know why my cron job is not running. Even though if I manually run the custom command, it works. This is what the cronjob file looks like when I do crontab -e
.
1 * * * * cd /Applications/MAMP/htdocs/projectName/app/console/Commands && php artisan schedule:run >> /dev/null 2>&1
when I run php artisan schedule:run
I get, No scheduled commands are ready to run.
Edit:
This is what my command class looks like:
class deletePics extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'picOfMonth:truncate';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Delete pics from old';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
PicOfMonth::where('created_at', '<', Carbon::now())->each(function ($item) {
$item->delete();
});
}
Also in my Kernel.php it looks like this:
class Kernel extends HttpKernel
{
protected $commands = [
deletePics::class
];
protected function schedule(Schedule $schedule)
{
$schedule->command('picOfMonth:truncate')->everyMinute();
}
CodePudding user response:
Your schedule commands should be in app\Console\Kernel.php and not Http\Kernel.php
CodePudding user response:
The cron schedule expression you are using, executes the job every first minute after an hour. For example:
- 15:01
- 16:01
- 17:01
You are probably looking for an expression that runs every minute. If that's the case, you want * * * * *
.