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 21, 2023
1 parent bf6c9fd commit be6057d
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/utils/client.util.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit be6057d

Please sign in to comment.