Skip to content

fix: run query inline when no task worker is available (regression from #2, breaks CLI/console)#3

Merged
Chance-fyi merged 1 commit into
Chance-fyi:masterfrom
nirolee:fix/run-inline-without-task-worker
Jun 9, 2026
Merged

fix: run query inline when no task worker is available (regression from #2, breaks CLI/console)#3
Chance-fyi merged 1 commit into
Chance-fyi:masterfrom
nirolee:fix/run-inline-without-task-worker

Conversation

@nirolee

@nirolee nirolee commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Problem

#2 (released in v3.0.2) made the task timeout configurable, but to do so it removed the #[Task] attribute from SqlServerTask and replaced the dispatch with a direct TaskExecutor->execute() call.

The original #[Task] aspect (Hyperf\Task\Aspect\TaskAspect) guarded the dispatch:

if ($executor->isTaskEnvironment()) {
    return $proceedingJoinPoint->process(); // run inline, no dispatch
}

runInTaskWorker() dropped that guard, so it now always calls TaskExecutor->execute(). When there is no Swoole server running — e.g. a console command via bin/hyperf.php ..., where TaskExecutor::$server is null and isTaskEnvironment() is its default trueexecute() throws:

The server does not support task.

So any SQL Server query issued from a command / CLI context (which worked fine before v3.0.2) now fails. Queries from the HTTP/cron server are unaffected because a task worker exists there.

Fix

Restore the inline-execution path: when TaskExecutor::isTaskEnvironment() is true (no server to offload to — CLI/console — or we are already inside a task worker), run the SqlServerTask method inline instead of dispatching; otherwise dispatch with the configured task_timeout as before.

This mirrors the original TaskAspect behaviour while keeping the configurable timeout from #2. Backward compatible.

@Chance-fyi
Chance-fyi merged commit 4d537dd into Chance-fyi:master Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants