luiswagener/symfony-cron-bundle

Scheduled background jobs for Symfony applications, with persistent tracking of execution history.

Maintainers

Package info

github.com/luiswagener/symfony-cron

Type:symfony-bundle

pkg:composer/luiswagener/symfony-cron-bundle

Transparency log

Statistics

Installs: 9

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.1 2026-06-10 10:43 UTC

This package is auto-updated.

Last update: 2026-07-16 08:46:15 UTC


README

Cron framework for Symfony applications. Register cron jobs with a single attribute, run them from a single minutely server cron, and persist last-run timestamps in the database.

Installation

composer require luiswagener/symfony-cron-bundle

Register the bundle in config/bundles.php:

Luiswagener\SymfonyCronBundle\SymfonyCronBundle::class => ['all' => true],

Create the database table:

php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate

Doctrine must have auto_mapping: true (Symfony default) so the bundle entity is discovered automatically.

Server cron

Configure one minutely cron job on your server:

* * * * * /usr/bin/php /path/to/your-app/bin/console cron:run

Defining cron jobs

Place a class anywhere under src/ and annotate it with #[AsCronJob]. No service registration or tagging is required — standard Symfony autowiring picks it up automatically.

use Luiswagener\SymfonyCronBundle\Attribute\AsCronJob;

#[AsCronJob('hourly')]
final class CleanupExpiredTokensCron
{
    public function __construct(private TokenRepository $tokens) {}

    public function __invoke(): void
    {
        $this->tokens->deleteExpired();
    }
}

Supported intervals

  • Presets: minutely, hourly, daily, weekly, monthly, yearly
  • Cron expressions: 0 * * * *, */5 * * * *
  • Human-readable: 1 minute, every 5 minutes, 1 hour

Command usage

php bin/console cron:run
php bin/console cron:run "App\\Cron\\CleanupExpiredTokensCron"
php bin/console cron:run --force
php bin/console cron:run "App\\Cron\\CleanupExpiredTokensCron" --force

Skipping execution

Throw CronExecutionSkippedException to skip a job without updating last_run:

use Luiswagener\SymfonyCronBundle\Exception\CronExecutionSkippedException;

public function __invoke(string $scope): void
{
    if ($scope !== Cron::SCOPE_CLI) {
        throw new CronExecutionSkippedException();
    }
}

License

MIT