mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-02 03:37:44 +08:00
Fixed bug that property $workerId
does not works in annotation @Task
. (#3674)
This commit is contained in:
parent
085f1cd671
commit
69ff4eb6cc
@ -6,6 +6,7 @@
|
||||
|
||||
- [#3667](https://github.com/hyperf/hyperf/pull/3667) Fixed bug that the crontab rule like `10-12/1,14-15/1` does not works.
|
||||
- [#3669](https://github.com/hyperf/hyperf/pull/3669) Fixed bug that the crontab rule without backslash like `10-12` does not works.
|
||||
- [#3674](https://github.com/hyperf/hyperf/pull/3674) Fixed bug that property `$workerId` does not works in annotation `@Task`.
|
||||
|
||||
## Optimized
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
- [#3667](https://github.com/hyperf/hyperf/pull/3667) 修复形如 `10-12/1,14-15/1` 的定时任务规则无法正常使用的问题。
|
||||
- [#3669](https://github.com/hyperf/hyperf/pull/3669) 修复了没有反斜线形如 `10-12` 的定时任务规则无法正常使用的问题。
|
||||
- [#3674](https://github.com/hyperf/hyperf/pull/3674) 修复 `@Task` 注解中,参数 `$workerId` 无法正常使用的问题。
|
||||
|
||||
## 优化
|
||||
|
||||
|
@ -101,6 +101,13 @@ $result = $task->handle(Coroutine::id());
|
||||
|
||||
> 使用 `@Task` 注解时需 `use Hyperf\Task\Annotation\Task;`
|
||||
|
||||
注解支持以下参数
|
||||
|
||||
| 配置 | 类型 | 默认值 | 备注 |
|
||||
| :------: | :---: | :----: | :------------------------------------------------: |
|
||||
| timeout | int | 10 | 任务执行超时时间 |
|
||||
| workerId | int | -1 | 指定投递的 Task 进程 ID (-1 代表随机投递到空闲进程) |
|
||||
|
||||
## 附录
|
||||
|
||||
Swoole 暂时没有协程化的函数列表
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
- [#3667](https://github.com/hyperf/hyperf/pull/3667) 修復形如 `10-12/1,14-15/1` 的定時任務規則無法正常使用的問題。
|
||||
- [#3669](https://github.com/hyperf/hyperf/pull/3669) 修復了沒有反斜線形如 `10-12` 的定時任務規則無法正常使用的問題。
|
||||
- [#3674](https://github.com/hyperf/hyperf/pull/3674) 修復 `@Task` 註解中,參數 `$workerId` 無法正常使用的問題。
|
||||
|
||||
## 優化
|
||||
|
||||
|
@ -101,6 +101,13 @@ $result = $task->handle(Coroutine::id());
|
||||
|
||||
> 使用 `@Task` 註解時需 `use Hyperf\Task\Annotation\Task;`
|
||||
|
||||
註解支持以下參數
|
||||
|
||||
| 配置 | 類型 | 默認值 | 備註 |
|
||||
| :------: | :---: | :----: | :------------------------------------------------: |
|
||||
| timeout | int | 10 | 任務執行超時時間 |
|
||||
| workerId | int | -1 | 指定投遞的 Task 進程 ID (-1 代表隨機投遞到空閒進程) |
|
||||
|
||||
## 附錄
|
||||
|
||||
Swoole 暫時沒有協程化的函數列表
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
- [#3667](https://github.com/hyperf/hyperf/pull/3667) 修復形如 `10-12/1,14-15/1` 的定時任務規則無法正常使用的問題。
|
||||
- [#3669](https://github.com/hyperf/hyperf/pull/3669) 修復了沒有反斜線形如 `10-12` 的定時任務規則無法正常使用的問題。
|
||||
- [#3674](https://github.com/hyperf/hyperf/pull/3674) 修復 `@Task` 註解中,引數 `$workerId` 無法正常使用的問題。
|
||||
|
||||
## 優化
|
||||
|
||||
|
@ -101,6 +101,13 @@ $result = $task->handle(Coroutine::id());
|
||||
|
||||
> 使用 `@Task` 註解時需 `use Hyperf\Task\Annotation\Task;`
|
||||
|
||||
註解支援以下引數
|
||||
|
||||
| 配置 | 型別 | 預設值 | 備註 |
|
||||
| :------: | :---: | :----: | :------------------------------------------------: |
|
||||
| timeout | int | 10 | 任務執行超時時間 |
|
||||
| workerId | int | -1 | 指定投遞的 Task 程序 ID (-1 代表隨機投遞到空閒程序) |
|
||||
|
||||
## 附錄
|
||||
|
||||
Swoole 暫時沒有協程化的函式列表
|
||||
|
@ -60,13 +60,15 @@ class TaskAspect extends AbstractAspect
|
||||
}
|
||||
|
||||
$timeout = 10;
|
||||
$workerId = -1;
|
||||
$metadata = $proceedingJoinPoint->getAnnotationMetadata();
|
||||
/** @var Task $annotation */
|
||||
$annotation = $metadata->method[Task::class] ?? $metadata->class[Task::class] ?? null;
|
||||
if ($annotation instanceof Task) {
|
||||
$timeout = $annotation->timeout;
|
||||
$workerId = $annotation->workerId;
|
||||
}
|
||||
|
||||
return $executor->execute(new TaskMessage([$class, $method], $arguments), $timeout);
|
||||
return $executor->execute(new TaskMessage([$class, $method], $arguments, $workerId), $timeout);
|
||||
}
|
||||
}
|
||||
|
@ -23,9 +23,15 @@ class Task
|
||||
*/
|
||||
public $arguments;
|
||||
|
||||
public function __construct($callback, array $arguments = [])
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $workerId;
|
||||
|
||||
public function __construct($callback, array $arguments = [], int $workerId = -1)
|
||||
{
|
||||
$this->callback = $callback;
|
||||
$this->arguments = $arguments;
|
||||
$this->workerId = $workerId;
|
||||
}
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ class TaskExecutor
|
||||
throw new TaskExecuteException('The server does not support task.');
|
||||
}
|
||||
|
||||
$taskId = $this->server->task($task);
|
||||
$taskId = $this->server->task($task, $task->workerId);
|
||||
if ($taskId === false) {
|
||||
throw new TaskExecuteException('Task execute failed.');
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user