andrewdyer/scheduler

Schedule events with this framework-agnostic cron scheduler, which can be easily integrated into your existing project or run as a standalone command scheduler.

v1.0.0 2021-09-16 12:59 UTC

This package is auto-updated.

Last update: 2024-09-16 19:59:10 UTC


README

Schedule jobs with this framework-agnostic cron scheduler, which can be easily integrated into your existing project or run as a standalone command scheduler.

License

Licensed under MIT. Totally free for private or commercial projects.

Installation

composer require andrewdyer/scheduler

Usage

// SendReminderJob.php
namespace App\Jobs;

use Anddye\Scheduler\AbstractJob;

class SendReminderJob extends AbstractJob
{
    public function handle(): void
    {
        // TODO: Send reminder to user somehow
    }
}
// index.php
$scheduler = new Anddye\Scheduler\Scheduler();

// At every 45th minute, run the send reminder job.
$scheduler->addJob(new App\Jobs\SendReminderJob())->setExpression('*/45 * * * *');

// add more jobs ...

$scheduler->run();

Job Frequencies

Combining Job Frequencies

// At minute 0 past hour 2 and 14 on Monday
$scheduler->addJob(new App\Jobs\SendReminderJob())->dailyTwice(2, 14)->mondays();
// At every 15th minute on Friday
$scheduler->addJob(new App\Jobs\SendReminderJob())->everyFifteenMinutes()->fridays();
// At every minute on Tuesday, Thursday, and Saturday
$scheduler->addJob(new App\Jobs\SendReminderJob())->everyMinute()->days(2, 4, 6);
// At minute 45 on Monday, Tuesday, Wednesday, Thursday, and Friday
$scheduler->addJob(new App\Jobs\SendReminderJob())->hourlyAt(45)->weekdays();
// At minute 1 on Monday, Wednesday, and Friday
$scheduler->addJob(new App\Jobs\SendReminderJob())->hourly()->days(1,3,5);