luag2124
Set a Cron Job in Laravel
Hello,
I just read this post: https://blog.railway.app/p/cron-jobs and I am trying to create and run a cron job in my laravel application.
Does anyone has any idea of how this can be done in a laravel project?
I created a file named "crone.ts" in the root directory with the next code:
const cron = require('node-cron');
const shell = require('shelljs');
// Schedule tasks to be run on the server.
cron.schedule('* * * * *', function() {
console.log('Running cronjobs');
shell.exec('php artisan schedule:run >> /dev/null 2>&1');
});
I created a task in the Laravel scheduler (.\app\Console\Kernel.php) with the next code:
$schedule->call(function () {
info("called every minute");
})->everyMinute();
And I modified my npm start script, so it now is:
"start": "php artisan serve && node /app/cron.ts&"
But I still can't make it work, any help would be really appreciated.
27 replies