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
}
}
推荐文章: