You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`
// 新建 HttpTaskServer
class HttpTaskServer extends HTTPServer
{
public function doTask(swoole_server $server, $data, $taskId, $workerId)
{
$this->dispatchJob($data);
}
/**
* @param $job
*/
protected function dispatchJob($job)
{
try {
$job->run();
} catch (Throwable $exception) {
if ($job instanceof TaskInterface) {
dispatcher()->queue($job);
}
logger()->error($exception);
}
}
}
// 新建投放task处理类
class TaskDispatcher
{
public function task(TaskInterface $job)
{
if (app()->has('server')) {
server()->getSwoole()->task($job);
} else {
$this->queue($job);
}
}
public function queue(TaskInterface $job)
{
if ($job instanceof AbstractJob) {
queue()->push($job);
}
}
}
// 调度
app()->get(TaskDispatcher::class)->task(
new NoticeAsync()
);
实现dotask, dofinish可以处理任务,但是不知道如何投递,能否支持投递到指定的task类处理呢
The text was updated successfully, but these errors were encountered: