承接 mybuilder/cronos-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

mybuilder/cronos-bundle

Composer 安装命令:

composer require mybuilder/cronos-bundle

包简介

Symfony 4/5/6 bundle which allows you to use @Cron annotations to configure cron to run your console commands.

关键字:

README 文档

README

A bundle for Symfony 4/5/6 that allows you to use @Cron annotations to configure when cron should run your console commands.

Uses the Cronos library to do the actual output and updating.

Installation

Install with composer

Run the composer require command:

$ composer require mybuilder/cronos-bundle

Enable the bundle

If you do not use Symfony Flex, enable the bundle in the config/bundles.php for Symfony 4/5/6:

return [
    MyBuilder\Bundle\CronosBundle\MyBuilderCronosBundle::class => ['all' => true],
];

Configure the bundle

You can add the following to your config/packages/my_builder_cronos.yaml (Symfony 4/5/6) to configure the package.

my_builder_cronos:
    exporter:
        key: unique-key
        mailto: cron@example.com
        path: /bin:/usr/local/bin
        executor: php
        console: bin/console
        shell: /bin/bash
option description
key Unique key that wraps all the cron configured for the current application.
mailto Sets the default email address for all cron output to go to.
path Sets the path for all commands in the crontab it works just like the shell PATH, but it does not inherit from your environment. That means you cannot use ~ or other shell expansions.
executor Allows you to specify a program that all commands should be passed to such as /usr/local/bin/php.
console Allows you to specify the console that all commands should be passed to such as bin/console.
shell Allows you to specify which shell each program should be run with.

Usage

The first step is to add the use case for the annotation to the top of the command you want to use the @Cron annotations in.

use MyBuilder\Bundle\CronosBundle\Annotation\Cron;

Then add to the phpdoc for the command class the '@Cron' annotation which tells cron when you want it to run. This example says it should be run on the web server, every 5 minutes, and we don't want to log any output.

/**
 * Command for sending our email messages from the database.
 *
 * @Cron(minute="/5", noLogs=true, server="web")
 */
class SendQueuedEmailsCommand extends Command {}

Specifying when to run

The whole point of cron is being able to specify when a script is run therefore there are a lot of options.

You should read the general cron info for a general idea of cron and what you can use in these time fields.

Please note You CANNOT use */ in the annotations, if you want */5 just put /5 and Cronos will automatically change it to */5.

Annotation examples

annotation description
@Cron(minute="/5") Every 5 minutes
@Cron(minute="5") At the 5th minute of each hour
@Cron(minute="5", hour="8") 5 minutes past 8am every day
@Cron(minute="5", hour="8", dayOfWeek="0") 5 minutes past 8am every Sunday
@Cron(minute="5", hour="8", dayOfMonth="1") 5 minutes past 8am on first of each month
@Cron(minute="5", hour="8", dayOfMonth="1", month="1") 5 minutes past 8am on first of of January
@Cron(minute="/5", params="--user=barman") Every 5 minutes, with a custom param

Building the cron

You should run bin/console cronos:dump and review what the cron file would look after it has been updated. If everything looks ok you can replace your crontab by running the command below.

bin/console cronos:replace

You can also limit which commands are included in the cron file by specifying a server, and it will then only show commands which are specified for that server.

Exporting the cron

bin/console cronos:dump --server=web
bin/console cronos:replace --server=web

Environment

You can choose which environment you want to run the commands in cron under like this.

bin/console cronos:replace --server=web --env=prod

Troubleshooting

  • When a cron line is executed it is executed with the user that owns the crontab, but it will not execute any of the users default shell files so all paths etc need to be specified in the command called from the cron line.
  • Your crontab will not be executed if you do not have usable shell in /etc/passwd
  • If your jobs don't seem to be running check the cron daemon is running, also check your username is in /etc/cron.allow and not in /etc/cron.deny.
  • Environmental substitutions do not work, you cannot use things like $PATH, $HOME, or ~/sbin.

Created by MyBuilder - Check out our blog for more insight into this and other open-source projects we release.

mybuilder/cronos-bundle 适用场景与选型建议

mybuilder/cronos-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 495.76k 次下载、GitHub Stars 达 87, 最近一次更新时间为 2013 年 10 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 mybuilder/cronos-bundle 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 87
  • Watchers: 13
  • Forks: 17
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-10-23