diff --git a/lib/utils/client.util.ts b/lib/utils/client.util.ts index 731fa61..61ae0aa 100644 --- a/lib/utils/client.util.ts +++ b/lib/utils/client.util.ts @@ -1,12 +1,21 @@ -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 () => { + try { + await client.connection?.close(); + } catch (e) { + console.error( + `Temporal client connection was not cleanly closed: ${e.stack}`, + ); + } + }; return client; } export function getWorkflowClient(options?: WorkflowClientOptions) { const client = new WorkflowClient(options); return assignOnAppShutdownHook(client); -} \ No newline at end of file +}