Merge branch 'roadrunner-zhangrunyu' into 'master'
Add roadrunner cron See merge request easycorp/zentaopms!1359
This commit is contained in:
@@ -1891,23 +1891,37 @@ class baseRouter
|
||||
$defaultParams[$name] = $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据PATH_INFO或者GET方式设置请求的参数。
|
||||
* Set params according PATH_INFO or GET.
|
||||
*/
|
||||
if($this->config->requestType != 'GET')
|
||||
if ('cli' === PHP_SAPI)
|
||||
{
|
||||
$this->setParamsByPathInfo($defaultParams);
|
||||
if ($this->params)
|
||||
{
|
||||
$this->params = array_merge($defaultParams, $this->params);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->params = $defaultParams;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->setParamsByGET($defaultParams);
|
||||
}
|
||||
/**
|
||||
* 根据PATH_INFO或者GET方式设置请求的参数。
|
||||
* Set params according PATH_INFO or GET.
|
||||
*/
|
||||
if($this->config->requestType != 'GET')
|
||||
{
|
||||
$this->setParamsByPathInfo($defaultParams);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->setParamsByGET($defaultParams);
|
||||
}
|
||||
|
||||
if($this->config->framework->filterParam == 2)
|
||||
{
|
||||
$_GET = validater::filterParam($_GET, 'get');
|
||||
$_COOKIE = validater::filterParam($_COOKIE, 'cookie');
|
||||
if($this->config->framework->filterParam == 2)
|
||||
{
|
||||
$_GET = validater::filterParam($_GET, 'get');
|
||||
$_COOKIE = validater::filterParam($_COOKIE, 'cookie');
|
||||
}
|
||||
}
|
||||
|
||||
/* 调用该方法 Call the method. */
|
||||
|
||||
+20
-6
@@ -134,9 +134,12 @@ class cron extends control
|
||||
*/
|
||||
public function ajaxExec($restart = false)
|
||||
{
|
||||
ignore_user_abort(true);
|
||||
set_time_limit(0);
|
||||
session_write_close();
|
||||
if ('cli' !== PHP_SAPI)
|
||||
{
|
||||
ignore_user_abort(true);
|
||||
set_time_limit(0);
|
||||
session_write_close();
|
||||
}
|
||||
/* Check cron turnon. */
|
||||
if(empty($this->config->global->cron)) die();
|
||||
|
||||
@@ -183,11 +186,21 @@ class cron extends control
|
||||
/* Skip cron that status is running and run time is less than max. */
|
||||
if($cronInfo->status == 'running' and (time() - strtotime($cronInfo->lastTime)) < $this->config->cron->maxRunTime) continue;
|
||||
/* Skip cron that last time is more than this cron time. */
|
||||
if($cronInfo->lastTime > $cron['time']->format(DT_DATETIME1)) die();
|
||||
if ('cli' === PHP_SAPI)
|
||||
{
|
||||
if($cronInfo->lastTime >= $cron['time']->format(DT_DATETIME1)) continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if($cronInfo->lastTime > $cron['time']->format(DT_DATETIME1)) die();
|
||||
}
|
||||
|
||||
if($now > $cron['time'])
|
||||
{
|
||||
$this->cron->changeStatus($id, 'running');
|
||||
if (!$this->cron->changeStatusRunning($id, $cronInfo->lastTime))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$parsedCrons[$id]['time'] = $cron['cron']->getNextRunDate();
|
||||
|
||||
/* Execution command. */
|
||||
@@ -239,11 +252,12 @@ class cron extends control
|
||||
sleep($sleepTime);
|
||||
|
||||
/* Break while. */
|
||||
if(connection_status() != CONNECTION_NORMAL) break;
|
||||
if('cli' !== PHP_SAPI && connection_status() != CONNECTION_NORMAL) break;
|
||||
if(((time() - $startedTime) / 3600 / 24) >= $this->config->cron->maxRunDays) break;
|
||||
}
|
||||
|
||||
/* Revert cron status to stop. */
|
||||
$this->cron->markCronStatus('stop', $configID);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -94,6 +94,27 @@ class cronModel extends model
|
||||
return dao::isError() ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change cron status to running
|
||||
*
|
||||
* @param int $cronID
|
||||
* @param string $lastTime
|
||||
* @access public
|
||||
* @return bool|int
|
||||
*/
|
||||
public function changeStatusRunning($cronID, $lastTime)
|
||||
{
|
||||
$data = new stdclass();
|
||||
$data->status = 'running';
|
||||
$data->lastTime = date(DT_DATETIME1);
|
||||
$rows = $this->dao->update(TABLE_CRON)->data($data)
|
||||
->where('id')->eq($cronID)
|
||||
->andWhere('status')->ne('running')
|
||||
->andWhere('lastTime')->eq($lastTime)
|
||||
->exec();
|
||||
return dao::isError() ? false : $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log cron.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
service:
|
||||
cron:
|
||||
command: php cron-worker.php
|
||||
process_num: 4
|
||||
exec_timeout: 0
|
||||
remain_after_exit: true
|
||||
restart_sec: 1
|
||||
@@ -0,0 +1,13 @@
|
||||
# 说明
|
||||
|
||||
## 环境安装
|
||||
|
||||
安装 RoadRunner: <https://roadrunner.dev/docs/intro-install>
|
||||
|
||||
Composer: `composer update`
|
||||
|
||||
## 启动服务
|
||||
|
||||
```shell
|
||||
rr serve
|
||||
```
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"require": {
|
||||
"spiral/roadrunner": "^2.6",
|
||||
"nyholm/psr7": "^1.4"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* The api router file of ZenTaoPMS.
|
||||
*
|
||||
* All request of entries should be routed by this router.
|
||||
*
|
||||
* @copyright Copyright 2009-2017 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
|
||||
* @license ZPL (http://zpl.pub/page/zplv12.html)
|
||||
* @author Gang Liu <liugang@cnezsoft.com>
|
||||
* @package ZenTaoPMS
|
||||
* @version $Id: index.php 5036 2013-07-06 05:26:44Z wyd621@gmail.com $
|
||||
* @link http://www.zentao.net
|
||||
*/
|
||||
/* Set the error reporting. */
|
||||
error_reporting(0);
|
||||
|
||||
/* Load the framework. */
|
||||
include '../framework/router.class.php';
|
||||
include '../framework/control.class.php';
|
||||
include '../framework/model.class.php';
|
||||
include '../framework/helper.class.php';
|
||||
|
||||
/* Log the time and define the run mode. */
|
||||
$startTime = getTime();
|
||||
|
||||
/* Instance the app. */
|
||||
$app = router::createApp('pms', dirname(__DIR__), 'router');
|
||||
|
||||
/* Run the app. */
|
||||
$common = $app->loadCommon();
|
||||
|
||||
$app->moduleName = 'cron';
|
||||
$app->methodName = 'ajaxExec';
|
||||
$app->setControlFile();
|
||||
$app->loadModule();
|
||||
Reference in New Issue
Block a user