It seems like the Laravel scheduler is running the tasks twice every minute. Here are a few things you can try to resolve this issue:
-
Check for overlapping tasks: Make sure that there are no other tasks or processes that are triggering the scheduler. Double-check your codebase for any other instances where the scheduler might be called.
-
Verify the cron job setup: Ensure that the cron job is set up correctly to run once per minute. You can do this by running the following command in your terminal:
crontab -lThis will display the current cron jobs. Verify that the Laravel scheduler command is set to run once per minute.
-
Clear Laravel's cache: Sometimes, cached data can cause unexpected behavior. Try clearing Laravel's cache by running the following command:
php artisan cache:clear -
Check for external triggers: Look for any external triggers or scripts that might be running the scheduler. Check your server logs or any other processes that might be interacting with the scheduler.
If none of these solutions work, you can try adding a lock to prevent the scheduler from running multiple times simultaneously. You can do this by modifying your Kernel.php file as follows:
use Illuminate\Console\Scheduling\Mutex;
class Kernel extends ConsoleKernel
{
protected function schedule(Schedule $schedule): void
{
$mutex = new Mutex();
if ($mutex->create()) {
$schedule->command('refresh:pollingdata')->everyMinute();
$schedule->command('check:pollingstatus')->everyFiveMinutes();
$mutex->release();
}
}
}
This will ensure that the scheduler only runs once at a time by acquiring and releasing a lock.
I hope this helps! Let me know if you have any further questions.