lingoda/cron-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

lingoda/cron-bundle

最新稳定版本:2.1.0

Composer 安装命令:

composer require lingoda/cron-bundle

包简介

Lingoda cron bundle

README 文档

README

This bundle allows scheduling of jobs that will execute in a different process than the process that triggered them

How to use

Either extend the ScheduleBaseCronJob abstract class or implement the CronJobInterface interface. These will automatically be recognized by your Symfony application. Then there's nothing left to do than execute the command bin/console lg:cron:trigger-due-jobs. This will send a message on the application's messenger bus for each recognized cron job that is due. Usually, this means that a message will be put on some sort of a queue which will then be picked up by a handler which will actually run the job.

When implementing a cron job, you shall not expect the cron to actually run at the scheduled times.

  • The queue might be unavailable or overloaded, and you can't predict the delay
  • The actual previous run time will be passed to your run method. Use it!
  • The job might be run manually. Or it might have been run manually previously. Even multiple times.

Triggering individual jobs

bin/console lg:cron:run-job App\\Cron\\SomeCronJobImplementation

Examples

Extending ScheduleBaseCronJob

class MyCronJob extends ScheduleBaseCronJob
{
    protected function getSchedule(): Schedule
    {
        // this job will execute every hour at the 30th minute
        return Schedule::everyHour(30);
    }

    public function run(): void
    {
        // do the job here
    }
}

Implementing CronJobInterface

class MyCronJob implements CronJobInterface
{
    public function run(): void
    {
        // do the job
    }

    public function shouldRun(DateTimeInterface $lastFinishTime = null): bool
    {
        // implement your own logic for determining if a job should
        // at a particular time or not
    }

    public function getLockTTL(): float
    {
        // before running, an expiring lock is acquired for each job to prevent
        // a job of the same type to run at the same time; with this method
        // the job can specify a custom expiry period in seconds for the lock

        return 30.0;
    }
    
    public function __toString(): string
    {
        // Here comes the cron expression as string, e.g. 30 1 * * *
        return '30 1 * * *';
    }
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-08-02