hyperia/yii2-cron

为 Yii2 自动阻塞/解锁控制台命令。一条命令无重复。

安装: 687

依赖者: 1

建议者: 0

安全: 0

星星: 0

关注者: 2

分支: 3

类型:yii2-extension

1.2.0 2022-04-07 12:10 UTC

This package is auto-updated.

Last update: 2024-09-08 12:47:27 UTC


README

提供一种逻辑和功能,用于阻塞控制台命令直到它们执行。如果服务器宕机,则在阻塞到期时解锁显示的命令。

使用方法

public function behaviors()
{
    return array(
        'LockUnLockBehavior' => array(
            'class' => 'hyperia\cron\commands\behaviors\LockUnLockBehavior',
            'timeLock' => 0 //Set time lock duration for command in seconds
        )
    );
}

任何命令都可以转换为守护进程

class AwesomeCommand extends DaemonController
{
    /**
     * Daemon name
     *
     * @return string
     */
    protected function daemonName(): string
    {
        return 'mail-queue';
    }

    /**
     * Run send mail
     */
    public function worker()
    {
        // Some logic that will be repeateble 
    }
}