timeout process stop events (#2349)

This commit is contained in:
Ahsan Virani 2021-10-21 19:50:38 +02:00 committed by GitHub
parent ba647fbc7b
commit d0403dd875
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 10 deletions

View file

@ -308,7 +308,7 @@ export interface IDiagnosticInfo {
export interface IInternalHooksClass { export interface IInternalHooksClass {
onN8nStop(): Promise<void>; onN8nStop(): Promise<void>;
onServerStarted(diagnosticInfo: IDiagnosticInfo): Promise<void>; onServerStarted(diagnosticInfo: IDiagnosticInfo): Promise<unknown[]>;
onPersonalizationSurveySubmitted(answers: IPersonalizationSurveyAnswers): Promise<void>; onPersonalizationSurveySubmitted(answers: IPersonalizationSurveyAnswers): Promise<void>;
onWorkflowCreated(workflow: IWorkflowBase): Promise<void>; onWorkflowCreated(workflow: IWorkflowBase): Promise<void>;
onWorkflowDeleted(workflowId: string): Promise<void>; onWorkflowDeleted(workflowId: string): Promise<void>;

View file

@ -11,7 +11,7 @@ import { Telemetry } from './telemetry';
export class InternalHooksClass implements IInternalHooksClass { export class InternalHooksClass implements IInternalHooksClass {
constructor(private telemetry: Telemetry) {} constructor(private telemetry: Telemetry) {}
async onServerStarted(diagnosticInfo: IDiagnosticInfo): Promise<void> { async onServerStarted(diagnosticInfo: IDiagnosticInfo): Promise<unknown[]> {
const info = { const info = {
version_cli: diagnosticInfo.versionCli, version_cli: diagnosticInfo.versionCli,
db_type: diagnosticInfo.databaseType, db_type: diagnosticInfo.databaseType,
@ -22,12 +22,15 @@ export class InternalHooksClass implements IInternalHooksClass {
execution_variables: diagnosticInfo.executionVariables, execution_variables: diagnosticInfo.executionVariables,
n8n_deployment_type: diagnosticInfo.deploymentType, n8n_deployment_type: diagnosticInfo.deploymentType,
}; };
await this.telemetry.identify(info);
await this.telemetry.track('Instance started', info); return Promise.all([
this.telemetry.identify(info),
this.telemetry.track('Instance started', info),
]);
} }
async onPersonalizationSurveySubmitted(answers: IPersonalizationSurveyAnswers): Promise<void> { async onPersonalizationSurveySubmitted(answers: IPersonalizationSurveyAnswers): Promise<void> {
await this.telemetry.track('User responded to personalization questions', { return this.telemetry.track('User responded to personalization questions', {
company_size: answers.companySize, company_size: answers.companySize,
coding_skill: answers.codingSkill, coding_skill: answers.codingSkill,
work_area: answers.workArea, work_area: answers.workArea,
@ -36,20 +39,20 @@ export class InternalHooksClass implements IInternalHooksClass {
} }
async onWorkflowCreated(workflow: IWorkflowBase): Promise<void> { async onWorkflowCreated(workflow: IWorkflowBase): Promise<void> {
await this.telemetry.track('User created workflow', { return this.telemetry.track('User created workflow', {
workflow_id: workflow.id, workflow_id: workflow.id,
node_graph: TelemetryHelpers.generateNodesGraph(workflow).nodeGraph, node_graph: TelemetryHelpers.generateNodesGraph(workflow).nodeGraph,
}); });
} }
async onWorkflowDeleted(workflowId: string): Promise<void> { async onWorkflowDeleted(workflowId: string): Promise<void> {
await this.telemetry.track('User deleted workflow', { return this.telemetry.track('User deleted workflow', {
workflow_id: workflowId, workflow_id: workflowId,
}); });
} }
async onWorkflowSaved(workflow: IWorkflowBase): Promise<void> { async onWorkflowSaved(workflow: IWorkflowBase): Promise<void> {
await this.telemetry.track('User saved workflow', { return this.telemetry.track('User saved workflow', {
workflow_id: workflow.id, workflow_id: workflow.id,
node_graph: TelemetryHelpers.generateNodesGraph(workflow).nodeGraph, node_graph: TelemetryHelpers.generateNodesGraph(workflow).nodeGraph,
}); });
@ -96,10 +99,16 @@ export class InternalHooksClass implements IInternalHooksClass {
} }
} }
void this.telemetry.trackWorkflowExecution(properties); return this.telemetry.trackWorkflowExecution(properties);
} }
async onN8nStop(): Promise<void> { async onN8nStop(): Promise<void> {
await this.telemetry.trackN8nStop(); const timeoutPromise = new Promise<void>((resolve) => {
setTimeout(() => {
resolve();
}, 3000);
});
return Promise.race([timeoutPromise, this.telemetry.trackN8nStop()]);
} }
} }