omnilight / yii2-scheduling

Scheduling extension for Yii2 framework
MIT License
317 stars 84 forks source link

onOneServer not working properly #79

Open mahran419 opened 3 months ago

mahran419 commented 3 months ago

Hello All

I tried using onOneServer to prevent multiple executions since our system uses auto-scaling. However, the cron job sometimes runs once, and other times it runs multiple times within a 1-microsecond difference. Here are the solutions I've tried, but nothing has worked:

1- I am trying to change the drivers from Redis & MySQL 2- decrease timeout from 30 to 10 3- using usleep for 5 milliseconds

console config:

'mutex' => [
            'class' => 'yii\redis\Mutex'
        ],

cronjobs implementation:

$schedule->call(function(\yii\console\Application $app) {
    \Yii::$app->sms->send("966**********", "One Server ".time());
})->everyMinute()->description("cron_every_minute")->onOneServer();