kfosoft/yii2-crontab

Yii2 Crontab

安装次数: 43

依赖项: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 0

开放问题: 0

类型:yii2扩展

20.10 2020-10-15 17:35 UTC

This package is auto-updated.

Last update: 2024-09-16 02:41:17 UTC


README

安装

使用Composer安装

运行以下命令之一

composer require kfosoft/yii2-crontab

配置

您需要将crontab配置添加到config/console.php配置文件中。示例文件

<?php

return [
    ...
    'bootstrap'           => [kfosoft\cron\CronManager::COMPONENT_NAME, ...],
    ...
    'components'          => [
        ...
        kfosoft\cron\CronManager::COMPONENT_NAME => [
            'class'     => kfosoft\cron\CronManager::class,
            'tab'       => [
                // Internal job without params
                [
                    'command'    => 'test/command',
                    'type'       => 'internal',
                    'expression' => '*/5 * * * *',
                ],
                // Internal job with params
                [
                    'command'    => 'test/command',
                    'type'       => 'internal',
                    'expression' => '*/1 * * * *',
                    'params'     => [
                        'attribute1' => 'test1',
                        'option1' => 'optTest1',
                    ],
                ],
                // External job example
                [
                    'command'    => '/bin/bash test -a --opt=123',
                    'type'       => 'external',
                    'expression' => '*/1 * * * *',
                ],
            ],
        ],
        ...
    ]
    ...
];

使用方法

bin/yii cron

Supervisor配置

[program:yii2-cron]
command=/fullpath/to/bin/yii cron 
autostart=true
autorestart=true
user=user_name_or_id
redirect_stderr=true