mooseh
2 months ago

random schedule cron

Posted 2 months ago by mooseh

So i have an artisan that runs a backup to a remote server at 1AM

but this artisan backup runs from a lot of servers which means unsurprisingly the backup server itself is having a trouble accepting all these connection all at once.

as you can see below im trying to randomise the time between 01 and 03 AM and i understand that this might run twice in the 3 hour timeframe

will my lumen 5.4 app honour this code? or will it just cache its first result, or just not bother at all?

$schedule->command('backup:sync')->cron(random_cronhr(01,03));

the random_cronhr function

function random_cronhr($start, $finish)
{
    $minute = rand(0,60);
    $hour = rand($start, $finish);

    return "{$minute} {$hour} * * *";
}

Please sign in or create an account to participate in this conversation.