mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
Encapsulate better
This commit is contained in:
parent
c513335054
commit
b786d91841
|
@ -557,6 +557,10 @@ export class TaskBroker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether n8n should manage the runner's lifecycle, i.e. launch it on demand,
|
||||||
|
* keep it alive for a period of time, and shut it down when idle for too long.
|
||||||
|
*/
|
||||||
private get shouldManageLifecycle() {
|
private get shouldManageLifecycle() {
|
||||||
return (
|
return (
|
||||||
this.runnerConfig.mode === 'internal_childprocess' ||
|
this.runnerConfig.mode === 'internal_childprocess' ||
|
||||||
|
@ -564,8 +568,11 @@ export class TaskBroker {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async taskRequested(request: TaskRequest) {
|
/**
|
||||||
if (this.shouldManageLifecycle) {
|
* Whether the runner is ready to accept a task, waiting one to launch if needed.
|
||||||
|
* Only for modes where we manage the runner's lifecycle.
|
||||||
|
*/
|
||||||
|
private async isRunnerReady(request: TaskRequest) {
|
||||||
const { RunnerLifecycleManager } = await import('@/runners/runner-lifecycle-manager');
|
const { RunnerLifecycleManager } = await import('@/runners/runner-lifecycle-manager');
|
||||||
const lifecycleManager = Container.get(RunnerLifecycleManager);
|
const lifecycleManager = Container.get(RunnerLifecycleManager);
|
||||||
|
|
||||||
|
@ -575,12 +582,18 @@ export class TaskBroker {
|
||||||
const error = ensureError(e);
|
const error = ensureError(e);
|
||||||
this.logger.error('Failed to start task runner', { error });
|
this.logger.error('Failed to start task runner', { error });
|
||||||
this.handleRunnerReject(request.requestId, `Task runner unavailable: ${error.message}`);
|
this.handleRunnerReject(request.requestId, `Task runner unavailable: ${error.message}`);
|
||||||
return;
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
lifecycleManager.updateLastActivityTime();
|
lifecycleManager.updateLastActivityTime();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async taskRequested(request: TaskRequest) {
|
||||||
|
if (this.shouldManageLifecycle && !(await this.isRunnerReady(request))) return;
|
||||||
|
|
||||||
this.pendingTaskRequests.push(request);
|
this.pendingTaskRequests.push(request);
|
||||||
this.settleTasks();
|
this.settleTasks();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue