定制 luiswagener/symfony-cron-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

luiswagener/symfony-cron-bundle

最新稳定版本:0.1

Composer 安装命令:

composer require luiswagener/symfony-cron-bundle

包简介

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

README 文档

README

Contao-style 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

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固