Workerman在thinkphp5.1使用,定时器部分方法运行不起来

部署到服务器上面,3600,7200这样的无法运行,30,60这样就可以运行;因为公司项目其他业务代码所以已删除,有人遇到这样的问题吗?比如confirm方法无法更新到数据。本地运行可以。奇了怪了。

use Workerman\Worker;
use think\console\Input;
use Workerman\Lib\Timer;
use think\console\Output;
use think\console\Command;
use think\console\input\Option;
use think\console\input\Argument;

class Fastorder extends Command
{
    protected function configure()
    {
        $this->setName('fast:order')
            ->addArgument('action', Argument::OPTIONAL, "start|stop|restart|reload|status|connections", 'start')
            ->addOption('daemon', 'd', Option::VALUE_NONE, 'Run the workerman server in daemon mode.')
            ->setDescription('Fast order refund planning task');
    }

    protected function execute(Input $input, Output $output)
    {
        $action = $input->getArgument('action');
        if (DIRECTORY_SEPARATOR !== '\\') {
            if (!in_array($action, ['start', 'stop', 'reload', 'restart', 'status', 'connections'])) {
                $output->writeln("<error>Invalid argument action:{$action}, Expected start|stop|restart|reload|status|connections .</error>");
                return false;
            }
            global $argv;
            array_shift($argv);
            array_shift($argv);
            array_unshift($argv, 'think', $action);
        } elseif ('start' != $action) {
            $output->writeln("<error>Not Support action:{$action} on Windows.</error>");
            return false;
        }

        if ('start' == $action) {
            $output->writeln('Starting GatewayWorker server...');
        }

        // 启动计划任务
        $this->plan();
        Worker::runAll();
    }

    // 初始化 计划任务 进程
    public function plan()
    {
        // 全局静态属性
        if ($this->input->hasOption('daemon')) {
            // 以daemon(守护进程)方式运行
            Worker::$daemonize = true;
        }
        Worker::$pidFile = '/var/run/fastorder.pid';
        $worker = new Worker();
        $worker->count = 1;
        $worker->onWorkerStart = function ($worker) {
            echo "\r\n";
            echo "Fastorder 计划任务 启动成功";
            echo "\r\n";
            Timer::add(300, array($this, 'order'));
            Timer::add(60, array($this, 'noPayToUser'));
            Timer::add(40, array($this, 'dispatchCancel'));
            Timer::add(60, array($this, 'orderNoCourier'));
            Timer::add(60, array($this, 'refund'));
            Timer::add(60, array($this, 'OrderAdditionalRefund'));
            Timer::add(60, array($this, 'orderNoCourierNoticeCourier'));
            Timer::add(120, array($this, 'orderNeedAddTip'));
            Timer::add(120, array($this, 'orderServiceNoticeUserAndCourier'));
            Timer::add(3600, array($this, 'confirm'));
            Timer::add(3600, array($this, 'updateUserCard'));
            Timer::add(3600, array($this, 'highPraise'));
            Timer::add(60, array($this, 'wechatTransfer'));
            Timer::add(7200, array($this, 'delorder'));
            Timer::add(3600, array($this, 'updateOrderRefund'));
        };
    }

    public function order()
    {
        // code
    }

    public function noPayToUser()
    {
        // code
    }

    public function orderNoCourier()
    {
        // code
    }

    public function dispatchCancel()
    {
        // code
    }

    public function orderNeedAddTip()
    {
        // code
    }

    private function getOrderNoCourier($type = 0)
    {
        // code
    }

    public function orderNoCourierNoticeCourier()
    {
        // code
    }

    public function orderFindCourier($order, $type = 0)
    {
        // code
    }


    public function orderDispatchCourier($courier, $order, $type = 0)
    {
        // code
    }

    public function refund()
    {
        // code
    }

    public function OrderAdditionalRefund()
    {
        // code
    }

    public function confirm()
    {
        // code
       Db::name('debug')->insert(['content' => '什么时候运行', 'ctime' => time()]);
    }

    public function highPraise()
    {
        // code
    }

    public function orderServiceNoticeUserAndCourier()
    {
        // code
    }

    public function wechatTransfer()
    {
        // code
    }

    public function updateUserCard()
    {
        // code
    }

    public function delorder()
    {
        // code
    }

    public function updateOrderRefund()
    {
        // code
    }
}
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 1

workerman 没用过,记得文档写,同一个进程,同一个时间只能有一个定时任务在运行。这么多业务处理,可以尝试分离出去然后队列处理。

6个月前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!