buzzingpixel/craft-scheduler
最新稳定版本:1.0.0
Composer 安装命令:
composer require buzzingpixel/craft-scheduler
包简介
Schedule tasks to run in Craft
README 文档
README
If you would like to programmatically schedule tasks to run in Craft CMS, this is the module for you! Just set up a cron to call the command every minute, then anything you schedule to run by hooking into the event will get run on the schedule you define.
Here's how to use it:
- In your craft project, run
composer require buzzingpixel/craft-scheduler - Then run
php craft plugin/install craft-scheduler - Now hook into the
RetrieveScheduleevent to add items to the schedule
The RetrieveSchedule event
The RetrieveSchedule event is how you add runners to the schedule. Here's a demo:
use BuzzingPixel\CraftScheduler\ScheduleRetrieval\RetrieveSchedule; use BuzzingPixel\CraftScheduler\ScheduleRetrieval\RetrieveScheduleEvent; use BuzzingPixel\CraftScheduler\ScheduleRetrieval\ScheduleConfigItem; use BuzzingPixel\CraftScheduler\Frequency; use yii\base\Event; Event::on( RetrieveSchedule::class, RetrieveSchedule::EVENT_RETRIEVE_SCHEDULE, static function (RetrieveScheduleEvent $e): void { $e->scheduleConfigItems()->addItem(item: new ScheduleConfigItem( className: SomeClass::class, // The class to run runEvery: Frequency::ALWAYS, // How often to run it method: 'myOptionalMethod', // Specify method on the class to call, defaults to __invoke resolveWith: SomeContainer::class, // Optionally provide your own ContainerInterface implementation. Defaults to the Yii container (or whatever default container you specify, see below) )); $e->scheduleConfigItems()->addItem(item: new ScheduleConfigItem( className: SomeOtherClass::class, runEvery: Frequency::HOUR, )); } );
The SetDefaultContainer event
The scheduler allows you to provide your own ContainerInterface implementation as the default. If no default is specified, Craft Scheduler's Yii Container implementation (a wrapper around the Yii container that implements the PSR ContainerInterface) will be used.
use BuzzingPixel\CraftScheduler\CraftSchedulerPlugin; use BuzzingPixel\CraftScheduler\ScheduleRetrieval\SetDefaultContainerEvent; use DI\ContainerBuilder; use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\ResponseInterface; use Slim\App; use Slim\Psr7\Factory\ResponseFactory; use yii\base\Event; use function DI\autowire; Event::on( CraftSchedulerPlugin::class, CraftSchedulerPlugin::EVEN_SET_DEFAULT_CONTAINER, static function (SetDefaultContainerEvent $e) { $containerBuilder = (new ContainerBuilder()) ->useAnnotations(true) ->useAutowiring(true) ->ignorePhpDocErrors(true) ->addDefinitions([ ResponseFactoryInterface::class => autowire(ResponseFactory::class), ]); $container = $containerBuilder->build(); $e->setDefaultContainer($container); } );
buzzingpixel/craft-scheduler 适用场景与选型建议
buzzingpixel/craft-scheduler 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 350 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 10 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 buzzingpixel/craft-scheduler 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 buzzingpixel/craft-scheduler 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 350
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2021-10-02