Skip to content

Commit e79dd47

Browse files
author
niulingyun
committed
2 parents 4b7df57 + afca02e commit e79dd47

22 files changed

Lines changed: 180 additions & 94 deletions

src/Client/Http/Client.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@ public function asyncDnsLookup($callBack, array $headers = [])
142142
if ($ip !== null) {
143143
$this->dnsLookupCallBack($ip);
144144
} else {
145-
$logId = $this->getContext()->getLogId();
146-
swoole_async_dns_lookup($this->urlData['host'], function ($host, $ip) use ($logId) {
145+
$requestId = $this->getContext()->getRequestId();
146+
swoole_async_dns_lookup($this->urlData['host'], function ($host, $ip) use ($requestId) {
147147
if ($ip === '127.0.0.0') { // fix bug
148148
$ip = '127.0.0.1';
149149
}
150150

151-
if (empty(getInstance()->scheduler->taskMap[$logId])) {
151+
if (empty(getInstance()->scheduler->taskMap[$requestId])) {
152152
return;
153153
}
154154

src/Client/RpcClient.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,15 @@ public function __construct($service)
109109
* 'timeout' => 1000, <选填,可被下级覆盖>
110110
* ]
111111
*/
112-
$config = getInstance()->config->get('params.service.' . $service, []);
112+
$config = getInstance()->config->get('service.' . $service, []);
113113
list($root,) = explode('.', $service);
114-
$config['host'] = getInstance()->config->get('params.service.' . $root . '.host', '');
114+
$config['host'] = getInstance()->config->get('service.' . $root . '.host', '');
115115
if ($config['host'] === '') {
116116
throw new Exception('Host configuration not found.');
117117
}
118118

119119
if (!isset($config['timeout'])) {
120-
$config['timeout'] = getInstance()->config->get('params.service.' . $root . '.timeout', 0);
120+
$config['timeout'] = getInstance()->config->get('service.' . $root . '.timeout', 0);
121121
}
122122

123123
// 赋值到类属性中.

src/Coroutine/CTask.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct($taskProxyData, $id, $timeout)
3939
$this->taskProxyData = $taskProxyData;
4040
$this->id = $id;
4141
$profileName = $taskProxyData['message']['task_name'] . '::' . $taskProxyData['message']['task_fuc_name'];
42-
$this->requestId = $this->getContext()->getLogId();
42+
$this->requestId = $this->getContext()->getRequestId();
4343

4444
$this->getContext()->getLog()->profileStart($profileName);
4545
getInstance()->scheduler->IOCallBack[$this->requestId][] = $this;

src/Coroutine/Dns.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function __construct(Client $client, $timeout, $headers = [])
4040
$this->client = $client;
4141
$this->headers = $headers;
4242
$profileName = mt_rand(1, 9) . mt_rand(1, 9) . mt_rand(1, 9) . '#dns-' . $this->client->urlData['host'];
43-
$this->requestId = $this->getContext()->getLogId();
43+
$this->requestId = $this->getContext()->getRequestId();
4444

4545
getInstance()->scheduler->IOCallBack[$this->requestId][] = $this;
4646
$this->getContext()->getLog()->profileStart($profileName);

src/Coroutine/Http.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function __construct(Client $client, $method, $path, $data, $timeout)
5353
$this->method = $method;
5454
$this->data = $data;
5555
$profileName = mt_rand(1, 9) . mt_rand(1, 9) . mt_rand(1, 9) . '#api-http://' . $this->client->urlData['host'] . ':' . $this->client->urlData['port'] . $this->path;
56-
$this->requestId = $this->getContext()->getLogId();
56+
$this->requestId = $this->getContext()->getRequestId();
5757

5858
$this->getContext()->getLog()->profileStart($profileName);
5959
getInstance()->scheduler->IOCallBack[$this->requestId][] = $this;

src/Coroutine/MySql.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function __construct($_mysqlAsynPool, $_bind_id = null, $_sql = null)
4545
$this->bindId = $_bind_id;
4646
$this->sql = $_sql;
4747
$this->request = $this->mysqlAsynPool->getAsynName() . '(' . str_replace("\n", " ", $_sql) . ')';
48-
$this->requestId = $this->getContext()->getLogId();
48+
$this->requestId = $this->getContext()->getRequestId();
4949

5050
$this->getContext()->getLog()->profileStart($this->request);
5151
getInstance()->scheduler->IOCallBack[$this->requestId][] = $this;

src/Coroutine/Redis.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function __construct($redisAsynPool, $name, $arguments)
7171
$this->name = $name;
7272
$this->arguments = $arguments;
7373
$this->request = mt_rand(1, 9) . mt_rand(1, 9) . mt_rand(1, 9) . '#' . $this->redisAsynPool->getAsynName() . '.' . $name;
74-
$this->requestId = $this->getContext()->getLogId();
74+
$this->requestId = $this->getContext()->getRequestId();
7575

7676
$this->getContext()->getLog()->profileStart($this->request);
7777
getInstance()->scheduler->IOCallBack[$this->requestId][] = $this;

src/Coroutine/Scheduler.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ public function __construct()
4141
return true;
4242
}
4343

44-
foreach ($this->IOCallBack as $logId => $callBacks) {
44+
foreach ($this->IOCallBack as $requestId => $callBacks) {
4545
foreach ($callBacks as $key => $callBack) {
4646
if ($callBack->ioBack) {
4747
continue;
4848
}
4949

5050
if ($callBack->isTimeout()) {
51-
if (!empty($this->taskMap[$logId])) {
52-
$this->schedule($this->taskMap[$logId]);
51+
if (!empty($this->taskMap[$requestId])) {
52+
$this->schedule($this->taskMap[$requestId]);
5353
}
5454
}
5555
}
@@ -144,9 +144,9 @@ public function schedule(Task $task, callable $callback = null)
144144
public function start(\Generator $routine, Controller $controller, callable $callBack = null)
145145
{
146146
$task = $controller->getObject(Task::class, [$routine, $controller, $callBack]);
147-
$logId = $controller->getContext()->getLogId();
148-
$this->IOCallBack[$logId] = [];
149-
$this->taskMap[$logId] = $task;
147+
$requestId = $controller->getContext()->getRequestId();
148+
$this->IOCallBack[$requestId] = [];
149+
$this->taskMap[$requestId] = $task;
150150
$this->schedule($task);
151151
}
152152
}

src/Coroutine/Sleep.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Sleep extends Base
2323
public function goSleep(int $mSec)
2424
{
2525
$this->__sleepTime = $mSec;
26-
$this->requestId = $this->getContext()->getLogId();
26+
$this->requestId = $this->getContext()->getRequestId();
2727
$this->setTimeout($mSec + 1000); //协程超时时间要比睡眠时间更长
2828

2929
getInstance()->scheduler->IOCallBack[$this->requestId][] = $this;

src/Coroutine/Task.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Task
4242
protected $controller;
4343

4444
/**
45-
* @var string 任务ID
45+
* @var int 任务ID
4646
*/
4747
protected $id;
4848

@@ -68,7 +68,7 @@ public function __construct(\Generator $routine, Controller &$controller, callab
6868
$this->routine = $routine;
6969
$this->controller = $controller;
7070
$this->stack = new \SplStack();
71-
$this->id = $this->getContext()->getLogId();
71+
$this->id = $this->getContext()->getRequestId();
7272
$this->callBack = $callBack;
7373
}
7474

@@ -134,6 +134,10 @@ public function setException(\Throwable $exception)
134134
public function run()
135135
{
136136
try {
137+
if (!$this->routine) {
138+
return;
139+
}
140+
137141
if ($this->exception) {
138142
throw $this->exception;
139143
}

0 commit comments

Comments
 (0)