bileto/cronner 问题修复 & 功能扩展

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

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

bileto/cronner

Composer 安装命令:

composer require bileto/cronner

包简介

Simple tool which helps with maintenance of cron tasks.

README 文档

README

Description

Simple tool which helps with maintenance of cron tasks.

It requires PHP >= 8.0 and Nette Framework >= 3.0.

Usage

It is very simple to use it because configuration is only in method annotations. Example class with tasks follows.

class CronTasks
{
    /**
     * @cronner-task E-mail sending
     * @cronner-period 1 day
     * @cronner-days working days
     * @cronner-time 23:30 - 05:00
     */
    public function sendEmails(): void
    {
        // Code which sends all your e-mails
    }


    /**
     * @cronner-task Important data replication
     * @cronner-period 3 hours
     */
    public function replicateImportantData(): void
    {
        // Replication code
    }
}

It is recommend to use compiler extension.

extension:
    cronner: Bileto\Cronner\DI\CronnerExtension

It does not require any configuration however your own implementation of timestamp storage could be better then the default storage. Your storage must be defined as a service in config.neon and Cronner will find it. However you can specify service manually if it is not autowireable.

cronner:
    timestampStorage: myCoolTimestampStorage

Or you can change the directory for default storage.

cronner:
    timestampStorage: Bileto\Cronner\TimestampStorage\FileStorage(%wwwDir%/../temp/cronner)

It is also possible to define maxExecutionTime for Cronner so you do not have make it by you own code (and probably for all your requests). Option criticalSectionTempDir can be change however the directory must be writable for php process. It is used to run each task only once at time.

At the end you would need to specify your task objects. It would be some service with high probability. You can add tag cronner.tasks to all services with Cronner tasks and those services will be bind automatically. However you can still add new task objects by your own using addTasks method.

Then you can use it very easily in Presenter

class CronPresenter extends \Nette\Application\UI\Presenter
{
    /**
     * @var \Bileto\Cronner\Cronner
     * @inject
     */
    public $cronner;

    
    public function actionCron(): void
    {
        $this->cronner->run();
    }
}

or in Command from Kdyby/Console.

Service configuration is also possible but it should not be used using new versions of Nette because extension usage is recommended and preferable way. However you will still need to call run method somewhere in your Presenter or console Command.

services:
    cronner: Bileto\Cronner\Cronner(Bileto\Cronner\TimestampStorage\FileStorage(%wwwDir%/../temp/cronner))
    setup:
    	- addTasks(new CronTasks())

Annotations

@cronner-task

This annotations is required for all public methods which should be used as a task. Its value is used as a name of task. If the value is missing the name is build from class name and method name.

If this annotation is single (for Cronner) in task method comment then the task is run every time when Cronner runs.

Note: Magic methods cannot be used as task (__construct, __sleep, etc.).

Example

/**
 * @cronner-task Fetches all public data from all registered social networks
 */

@cronner-period

Not required but recommended annotation which specifies period of task execution. The period is minimal time between two executions of the task. It's value can be anything what is acceptable for strtotime() function. The only restriction is usability with "+" sign before the time because it is added by Cronner automatically. So first day of this month is not acceptable however 1 month is acceptable.

Attention! The value of this annotation must not contain any sign (+ or -).

Example

/**
 * @cronner-period 1 day
 */

@cronner-days

Allows run the task only on specified days. Possible values are abbreviations of week day names. It means Mon, Tue, Wed, Thu, Fri, Sat and Sun. There are two shortcuts for easier usage: working days (Mon, Tue, Wed, Thu, Fri) and weekend (Sat and Sun) which are internally expanded to specific days. Multiple values must be separated by comma (Mon, Wed, Fri) or can be specified by range Mon-Thu.

Example

/**
 * @cronner-days working days, Sun
 */

@cronner-time

Specifies day time range (or ranges) in which the task can be run. It can be range or a specific minute. It uses 24 hour time model. Multiple values must be separated by comma.

The time can be defined over midnight as it is in following example.

Note: There is tolerance time of 5 seconds to run task as soon as possible if previous run have had slower start from any reason.

Example

/**
 * @cronner-time 11:00, 23:30 - 05:00
 */

bileto/cronner 适用场景与选型建议

bileto/cronner 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.22k 次下载、GitHub Stars 达 75, 最近一次更新时间为 2022 年 03 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「manager」 「cron」 「task」 「nette」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 bileto/cronner 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 bileto/cronner 我们能提供哪些服务?
定制开发 / 二次开发

基于 bileto/cronner 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 75
  • Watchers: 9
  • Forks: 18
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-03-29