Skip to content

Commit

Permalink
Merge pull request #15 from uniondrug/2.x
Browse files Browse the repository at this point in the history
2.x
  • Loading branch information
fuyibing authored May 28, 2018
2 parents efbcb9a + 996515f commit bbdd394
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Uniondrug\Framework\Container;
use Uniondrug\Http\Response;
use Uniondrug\Server\Task\Dispatcher;
use Uniondrug\Server\Utils\Connections;

/**
* Class Application.
Expand Down Expand Up @@ -127,6 +128,9 @@ protected function registerExceptionHandler()
*/
public function handleRequest(ServerRequestInterface $request)
{
// 处理业务前检测数据库连接,自动重连
Connections::testConnections();

try {
// 将PSR规范的HTTP请求放入容器,为了兼容处理
$this->setShared('PsrRequest', $request);
Expand Down
6 changes: 5 additions & 1 deletion src/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,13 @@ public function checkParent()
if (function_exists('posix_getppid')) {
$parentPid = posix_getppid();
if ($parentPid == 1) {
console()->debug('[checkParent] 父进程已经退出');

return false;
} else {
if (!swoole_process::kill($parentPid, 0)) {
if (!posix_kill($parentPid, 0)) {
console()->debug('[checkParent] 父进程已经不存在');

return false;
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/Servitization/OnTaskTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use swoole_server;
use Uniondrug\Packet\Json;
use Uniondrug\Server\Task\TaskHandler;
use Uniondrug\Server\Utils\Connections;

trait OnTaskTrait
{
Expand All @@ -18,6 +19,10 @@ trait OnTaskTrait
public function doTask(swoole_server $server, $data, $taskId, $workerId)
{
console()->debug("[Task] doTask: fromWorkerId=%d, taskId=%d, data=%s", $workerId, $taskId, $data);

// 测试数据库连接
Connections::testConnections();

try {
$task = Json::decode($data, true);
if ($task && isset($task['handler']) && is_a($task['handler'], TaskHandler::class, true)) {
Expand Down

0 comments on commit bbdd394

Please sign in to comment.