Randomize Command Execution Time with the Chaotic Schedule Package for Laravel

  • Published on 10 June, 2024
  • Words: 188

The chaotic-schedule package for Laravel allows you to randomize scheduled command execution time and date intervals via Pseudorandom number generators (PRNGs)

Randomize Command Execution Time with the Chaotic Schedule Package for Laravel

"Ever wanted to run your scheduled commands on random times of the day, or on certain days of the week? Or you may need to send some notifications not on fixed date times, but rather on random intervals hence it feels more human. Then this is the package you're looking for.

This Laravel packages enables you to run commands on random intervals and periods while respecting the boundaries set exclusively by you".

 

One use-case mentioned in the readme is sending user notifications or emails but sending them randomly to add a more personal human touch. Avoiding the sending of these messages at regular intervals at the same time would be more recognizably automated:

 

// Run a command daily on a random time between 08:15 and 11:42
$schedule->command('inspire')->daily()->atRandom('08:15','11:42');
 
// Run a command every Tuesday, Saturday and Sunday on a random time between 04:20 and 06:09
$schedule->command('your-command-signature:here')
    ->days([Schedule::TUESDAY, Schedule::SATURDAY, Schedule::SUNDAY])
    ->atRandom('04:20','06:09');

 

This package includes quite a few methods to define your random specifications based on several factors, such as:

 

  • - dailyAtRandom()
  • - hourlyAtRandom()
  • - hourlyMultipleAtRandom()
  • - randomDays()

 

You can learn more about this package, get full installation instructions, and view the source code on GitHub.

Antonio Jenaro

Antonio Jenaro

Web Developer

Filed in:

Source: Laravel news

Start the conversation

Become a member of Antonio Jenaro to start commenting.

Sign up now

Already a member? Sign in