peppeocchi / php-cron-scheduler

PHP cron job scheduler
MIT License
808 stars 143 forks source link

Schedules overlapping #98

Closed mshs013 closed 4 years ago

mshs013 commented 4 years ago

OnlyOne does not work, it runs every min. Bellow my code:

$scheduler->call(function () {
     //my custom code to get data from databse and send notification alert.
})->onlyOne('/var/www/html/storage/log');

Please help me to fix this.

peppeocchi commented 4 years ago

@mshs013 you can try by passing a custom identifier for the function. The identifier is used to create the lock file. And also make sure the scheduler can write to that folder. Did you see if it creates the lock files? If it doesn't then maybe the folder is not writable, of if it does it might be it generates a different id every time. To pass a custom identifier you can do

$scheduler->call(function () {
     //my custom code to get data from databse and send notification alert.
}, [], 'myUniqueFnIdentifier')->onlyOne('/var/www/html/storage/log');
mshs013 commented 4 years ago

@peppeocchi Now it works when I add custom identifier. Thank you ;)