Skip to content

Commit

Permalink
Squashing client close errors
Browse files Browse the repository at this point in the history
  • Loading branch information
clintonb committed Jun 22, 2023
1 parent bf6c9fd commit 35076bb
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/utils/client.util.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 35076bb

Please sign in to comment.