litvinab/cron-event
Composer 安装命令:
composer require litvinab/cron-event
包简介
Current symfony2 bundle generates events inside the application based on timers stored in DB.
关键字:
README 文档
README
Symfony2 bundle to set and run cron-based timers and events. It generates events inside the application based on timers stored in DB.
Currently bundle supports MongoDB only.
Steps to install and check
-
run command in project root folder:
composer require litvinab/cron-event -
add
new Litvinab\Bundle\CronEventBundle\CronEventBundle()inAppKernel.php -
setup cron task:
php app/console cron:runfor each minute -
for testing purposes add bundle test routes to
routing.yml:
cron:
resource: "@CronEventBundle/Resources/config/routing.yml"
prefix: /cron
-
To add test timer (1 minute timer) and event go to
http://your-domain/cron/ -
Added schedules will be displayed on this page:
http://your-domain/cron/showstatusfields should beunexpired -
Refresh
http://your-domain/cron/showpage after 1-2 minutes after point #5.statusfields should beexpiredit means that bundle works right.
!! Do not forget to remove test routes from routing.yml. It's not secure to leave it there.
Supported event types
timer - event in application will be triggered after N milliseconds.
event - event in application will be triggered in specified date and time.
How to use
1. Set event in your code
In controller:
// get cron manager $cronManager = $this->get('cron_event.manager'); // set timer with: human name, name, period // name of the symfony event: `cron_event.` + name $timer = $cronManager->setTimer('My timer', 'test_timer', 60);
2. Add cron event subscriber
Of course you are able to create event listeners if you wish.
services.yml:
services:
app.subscriber.cron:
class: AppBundle\EventSubscriber\CronSubscriber
calls:
- [setLogger, [@cron_event.logger]]
tags:
- { name: kernel.event_subscriber }
/YourBundle/EventSubscriber/CronSubscriber.php:
<?php namespace AppBundle\EventSubscriber; use Litvinab\Bundle\CronEventBundle\Events\CronEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * Class CronSubscriber */ class CronSubscriber implements EventSubscriberInterface { /** * @var Cron Logger */ private $logger; /** * Set cron logger * * @param $logger */ public function setLogger($logger) { $this->logger = $logger; } /** * Get subscribed events * * @return array */ public static function getSubscribedEvents() { return array( 'cron_event.test_timer' => array('onCronTestEvent', 0) ); } /** * Test event * * @param CronEvent $cronEvent */ public function onCronTestEvent(CronEvent $cronEvent) { // confirm that event is executed $this->logger->addInfo('onCronTestEvent'); // delete cron event from DB $cronEvent->delete(); } }
3. Check logs
CronEvent bundle providing it's own logger. Service name of logger is cron_event.logger.
onCronTestEvent string should be appeared in app/logs/cron.log file after 2-3 minutes.
Console Commands
cron:run - this command should be launched each minute or another period of time in crontab;
cron:list - list all schedules;
litvinab/cron-event 适用场景与选型建议
litvinab/cron-event 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 490 次下载、GitHub Stars 达 1, 最近一次更新时间为 2016 年 07 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「event」 「cron」 「Cron event」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 litvinab/cron-event 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 litvinab/cron-event 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 litvinab/cron-event 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Symfony bundle to monitor and execute commands
Scheduling extension for Yii2 framework
Monitoring for scheduled jobs
Symfony bundle for broadway/broadway.
Temporal frequency library
Scheduling extension for Yii2 framework
统计信息
- 总下载量: 490
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2016-07-18