diff --git a/lib/utils/client.util.ts b/lib/utils/client.util.ts index 731fa61..a4cd099 100644 --- a/lib/utils/client.util.ts +++ b/lib/utils/client.util.ts @@ -1,12 +1,20 @@ -import { OnApplicationShutdown } from "@nestjs/common"; -import { WorkflowClient, WorkflowClientOptions } from "@temporalio/client"; +import { OnApplicationShutdown } from '@nestjs/common'; +import { WorkflowClient, WorkflowClientOptions } from '@temporalio/client'; export function assignOnAppShutdownHook(client: WorkflowClient) { - (client as unknown as OnApplicationShutdown).onApplicationShutdown = client.connection.close; + (client as unknown as OnApplicationShutdown).onApplicationShutdown = + async () => + client.connection + ?.close() + .catch((reason) => + console.error( + `Temporal client connection was not cleanly closed: ${reason}`, + ), + ); return client; } export function getWorkflowClient(options?: WorkflowClientOptions) { const client = new WorkflowClient(options); return assignOnAppShutdownHook(client); -} \ No newline at end of file +}