abc/scheduler

Library for to manage schedules for repeated execution of tasks

0.2.2 2020-12-01 18:42 UTC

This package is not auto-updated.

Last update: 2024-12-11 15:13:26 UTC


README

A PHP library to process schedules base on CRON expressions.

Features:

  • Define schedules based on CRON expressions
  • Symfony Console Command to run scheduler
  • Simple integration by implementing two interfaces

Build Status

Note: This project is still experimental!

Installation

composer require abc/scheduler

Getting Started

  1. Define a schedule provider by implementing ProviderInterfacve.

    namespace Abc\Scheduler;
    
    interface ProviderInterface
    {
        /**
         * @return string The provider's name, used to bind a provider to processors
         */
        public function getName(): string;
    
        /**
         * @param int|null $limit
         * @param int|null $offset
         * @return ScheduleInterface[]
         */
        public function provideSchedules(int $limit = null, int $offset = null): array;
    
        public function save(ScheduleInterface $schedule): void;
    }
  2. Define a schedule processor by implementing ProcessorInterface.

    namespace Abc\Scheduler;
    
    /**
     * Process a schedule that is due.
     */
    interface ProcessorInterface
    {
        public function process(ScheduleInterface $schedule);
    }
  3. Bind Processor to Provider and initialize the ScheduleCommand

    use Abc\Scheduler\Scheduler;
    use Abc\Scheduler\Symfony\ScheduleCommand;
    
    $myProvider = new MyProvider();
    $myProcessor = new MyProcessor();
    
    $scheduler = new Scheduler();
    $scheduler->bind($myProvider, $myProcessor);
    
    $command = new ScheduleCommand($scheduler);
  4. Run the command

    bin/console abc:schedule

License

The MIT License (MIT). Please see License File for more information.