PHPackages                             bytespin/console-command-scheduler-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. bytespin/console-command-scheduler-bundle

ActiveSymfony-bundle[CLI &amp; Console](/categories/cli)

bytespin/console-command-scheduler-bundle
=========================================

Provides easy scheduling for symfony console commands using latest Symfony messenger/scheduler components

2.1.1(3w ago)0121MITPHPPHP &gt;=8.4

Since Mar 28Pushed 3w agoCompare

[ Source](https://github.com/ByteSpin/ConsoleCommandSchedulerBundle)[ Packagist](https://packagist.org/packages/bytespin/console-command-scheduler-bundle)[ Docs](https://github.com/ByteSpin/ConsoleCommandSchedulerBundle)[ RSS](/packages/bytespin-console-command-scheduler-bundle/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (69)Versions (34)Used By (0)

Copyright (c) 2023 Greg LAMY

This is a public project hosted on GitHub :

This bundle was originally developed as part of an ETL project.

ByteSpin/ConsoleCommandSchedulerBundle is a Symfony 6.3 simple bundle that allows you to schedule console commands easily:

- Use the latest messenger/scheduler Symfony 6.3+ components,
- Log all console commands data (last execution time, duration, return code) in database and log file,
- An admin interface is available with the help of EasyCorp/EasyAdmin bundle
- Specific events are available for deeper integration with your application and/or notification system
- An extendable notification system (by email)

Note

This project is still at beta state.

**Feel free to submit bug and/or pull requests!**

You can check the [CHANGELOG](CHANGELOG) to see the latest improvements and fixes.

Just keep in mind that I want to keep it as simple as possible!

Important

Version 1.0.13 requires schema update. Please run : `php php bin/console doctrine:schema:update --force`

Requirements
------------

[](#requirements)

- php 8.2+
- Symfony 6.3+

Installation
------------

[](#installation)

1. First install the bundle:

```
composer require bytespin/console-commande-scheduler-bundle
```

2. Then update the database schema:

```
php bin/console doctrine:schema:update --force
```

Updating the bundle
-------------------

[](#updating-the-bundle)

For now, the bundle still lacks a custom recipe to manage database schema upgrade when needed.

**Do not forget to update the database schema when updating the bundle**

The last version that includes schema modifications is : 1.1.0

Manual bundle registration
--------------------------

[](#manual-bundle-registration)

You will need to manually register the bundle in your application.

To do this, follow these steps:

1. Open the file `config/bundles.php` in your Symfony application.
2. Add the following line to the array returned by this file:

    ```
    ByteSpin\ConsoleCommandSchedulerBundle\ConsoleCommandSchedulerBundle::class => ['all' => true],
    ```
3. Save the file. Your bundle is now registered and ready to be used in your application.

Make sure to perform this step after you have installed the bundle using Composer, but before you use any of its features in your application.

Configuration
-------------

[](#configuration)

You will have to configure the entity manager to be used with the ByteSpin\\ConsoleCommandSchedulerBundle entities. This has to be done once after installation. We provide a script to automatise this step ; please run :

```
bin/console bytespin:configure-console-command-scheduler
```

If you prefer to do this by yourself, add the following lines just within your entity manager 'mappings:' key in doctrine.yaml :

```
# src/config/packages/doctrine.yaml
doctrine:
    dbal:
    (...)
    orm:
    (...)
        entity_managers:
            your_entity_manager:
            (...)
                mappings:
                  ByteSpin\ConsoleCommandSchedulerBundle:
                  is_bundle: false
                  type: attribute
                  dir: '%kernel.project_dir%/vendor/bytespin/console-command-scheduler-bundle/src/Entity'
                  prefix: ByteSpin\ConsoleCommandSchedulerBundle\Entity
                  alias: ByteSpin\ConsoleCommandSchedulerBundle

```

Important

If your project contains entities mapped to multiple entity managers, be careful to not use the auto\_mapping: true in your doctrine configuration.

This would prevent the getManagerForClass() function used in the bundle to get the correct entity manager to work properly!

In such case :

- Choose the correct entity manager when you run the configuration script,
- Be sure to remove the 'auto\_mapping: true' key from your doctrine.yaml (or set it to false),
- Be sure that ALL your entities are correctly mapped in the 'mappings:' sections of your doctrine.yaml

Reliability &amp; Validation (2.1+)
-----------------------------------

[](#reliability--validation-21)

A scheduled entry that cannot run must never take the scheduler down. Since 2.1:

- **Input validation** — the `Scheduler` entity carries a class-level constraint: the frequency must build a real recurring message for the chosen execution type. The classic trap (a cron expression such as `0 0 * * 1-5` typed into the *Frequency* interval field) is rejected in the admin form with an explicit hint instead of crashing the scheduler worker at runtime.
- **Fault isolation** — if an invalid entry still reaches the schedule build (e.g. a command removed after being scheduled), it is skipped with an error log and a `SchedulerEntryFaultedEvent` (`bytespin.scheduler.entry.faulted`); every other entry keeps running. The admin list shows a red **invalid** badge (with the reason) on skipped entries.
- **Linting** — dry-run every entry through the exact factory the scheduler uses:

```
bin/console bytespin:scheduler:lint
```

The command exits non-zero when an enabled entry cannot run — wire it into your CI or deploy pipeline.

- **Missed runs** — when the scheduler resumes after a downtime it runs at most **one** catch-up occurrence per task (cron-like semantics). Restore the previous replay-everything behavior with:

```
# config/packages/bytespin_console_command_scheduler.yaml
bytespin_console_command_scheduler:
    scheduler:
        process_only_last_missed_run: false
```

Hooking your monitoring on skipped entries:

```
use ByteSpin\ConsoleCommandSchedulerBundle\Event\SchedulerEntryFaultedEvent;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;

#[AsEventListener(event: SchedulerEntryFaultedEvent::NAME)]
final class SchedulerFaultListener
{
    public function __invoke(SchedulerEntryFaultedEvent $event): void
    {
        // $event->entry is the faulty Scheduler entity, $event->error the cause
    }
}
```

Tags Feature (Optional)
-----------------------

[](#tags-feature-optional)

The bundle supports an optional tags system that allows you to categorize and filter scheduled commands. This feature is **disabled by default** and requires configuration to enable.

### Enabling Tags

[](#enabling-tags)

1. Create a Tag entity in your application that implements `ByteSpin\ConsoleCommandSchedulerBundle\Model\TagInterface`:

```
