synolia/sylius-scheduler-command-plugin

调度命令插件。

安装数: 242,530

依赖项: 0

建议者: 0

安全性: 0

星标: 30

关注者: 12

分支: 20

开放问题: 11

类型:sylius-plugin

v3.6.0 2023-09-15 14:44 UTC

README

License CI - Analysis CI - Sylius Version Total Downloads

调度命令插件

在您的Sylius管理面板中安排Symfony命令。

命令列表

Commands

安排的命令列表

Scheduled Commands

特性

  • 查看计划中的命令列表
  • 添加、编辑、启用/禁用或删除安排的命令
  • 对于每个命令,您必须定义
    • 名称
    • 从Symfony命令列表中选择指定的命令
    • 基于Cron计划表达式,请参阅Cron格式
    • 输出日志文件前缀(可选)
    • 优先级(最高优先级)
  • 立即运行命令(在命令synolia:scheduler-run的下一次通过时)
  • 只运行一次命令(从历史页面点击启动命令按钮)
  • 直接从管理面板下载或实时查看日志文件
  • 使用工厂定义命令(例如从Doctrine迁移)

要求

安装

  1. 在您的composer.json中添加包及其依赖项

     composer config extra.symfony.allow-contrib true
     composer req synolia/sylius-scheduler-command-plugin
    
  2. 将迁移应用于您的数据库

     bin/console doctrine:migrations:migrate
    
  3. 在Crontab中启动Run命令

     * * * * * /_PROJECT_DIRECTORY_/bin/console synolia:scheduler-run
    
  4. (可选)显示人性化的cron表达式

     composer require lorisleiva/cron-translator
    
  5. 直到symfony/recipes-contrib更新到v3,您必须按照相同的文件夹架构将install/Application/config/{packages,routes}中的sylius_scheduler_command.yaml添加到您的项目中。

     cp -R vendor/synolia/sylius-scheduler-command-plugin/install/Application/config/packages/* config/packages/
     cp -R vendor/synolia/sylius-scheduler-command-plugin/install/Application/config/routes/* config/routes/
    

使用方法

  • 登录到管理面板
  • 在主菜单中点击“安排命令”部分下的“安排的命令”来管理您的安排命令
  • 在主菜单中点击“安排命令历史”部分下的“安排的命令历史”来查看命令的历史

数据集

在sylius数据集文件config/packages/sylius_fixtures.yaml中,您可以添加安排命令数据集到您的测试套件。

sylius_fixtures:
    suites:
        my_fixture_suite:
            fixtures:
                scheduler_command:
                    options:
                        scheduled_commands:
                            -
                                name: 'Reset Sylius'
                                command: 'sylius:fixtures:load'
                                cronExpression: '0 0 * * *'
                                logFilePrefix: 'reset'
                                priority: 0
                                enabled: true
                            -
                                name: 'Cancel Unpaid Orders'
                                command: 'sylius:cancel-unpaid-orders'
                                cronExpression: '0 0 * * *'
                                priority: 1
                                enabled: false

命令

synolia:scheduler-run

执行安排的命令。

  • 选项
    • –id(只运行特定的安排命令)

运行所有安排的命令: php bin/console synolia:scheduler-run

运行一个安排的命令: php bin/console synolia:scheduler-run –id=5

synolia:scheduler:purge-history

清除超过{X}天旧的安排命令历史。

  • 选项
    • –all(清除所有内容)
    • –days(保留天数)
    • –state(安排状态的数组)
    • –dry-run

示例:在7天后删除所有完成和错误的安排命令

php bin/console synolia:scheduler:purge-history --state=finished --state=error --days=7

可选服务

services:
...
    # By enabling this service, it will be requested to vote after the other EveryMinuteIsDueChecker checker.
    # Using some cloud providers, even if the master cron is set to run every minute, it is actually not run that often
    # This service allows you to set a soft threshold limit, so if your provider is actually running the master cron every 5 minutes
    # This service will execute the cron if we are still in the threshold limit ONLY IF it was not already executed another time in the same range.
    #
    # CONFIGURATION SCENARIO: cron set to be run at 01:07 in the scheduler command plugin
    #
    # SCENARIO CASES AT 1 CRON PASS EVERY 5 MINUTES FROM THE PROVIDER
    # cron passes at 01:04 - 1..5 minutes: IS NOT DUE
    # cron passes at 01:05 - 1..5 minutes: IS NOT DUE
    # cron passes at 01:06 - 1..5 minutes: IS NOT DUE
    # cron passes at 01:07 - 1..5 minutes: IS DUE (but it should already be handled by EveryMinuteIsDueChecker)
    # cron passes at 01:08 - 1..5 minutes: IS DUE
    # cron passes at 01:09 - 1..5 minutes: IS DUE #should not if another has started during the threshold period
    # cron passes at 01:10 - 1..5 minutes: IS DUE #should not if another has started during the threshold period
    # cron passes at 01:11 - 1..5 minutes: IS DUE #should not if another has started during the threshold period
    # cron passes at 01:12 - 1..5 minutes: IS DUE #should not if another has started during the threshold period
    # cron passes at 01:13 - 1..5 minutes: IS NOT DUE
    Synolia\SyliusSchedulerCommandPlugin\Checker\SoftLimitThresholdIsDueChecker:
        tags:
            - { name: !php/const Synolia\SyliusSchedulerCommandPlugin\Checker\IsDueCheckerInterface::TAG_ID }
        #optionnal, default value is 5 minutes
        arguments:
            $threshold: 5 #soft limit threshold in minutes

开发

查看如何贡献

许可证

此库受MIT许可证的约束。

鸣谢

Synolia开发。