-
Notifications
You must be signed in to change notification settings - Fork 88
/
log-sink-tester.ts
43 lines (37 loc) · 1.32 KB
/
log-sink-tester.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* Workflow used in test-sinks.ts to verify sink replay behavior
*
* Also tests workflow.taskInfo()
* @module
*/
import * as wf from '@temporalio/workflow';
// @@@SNIPSTART typescript-logger-sink-interface
import type { Sinks } from '@temporalio/workflow';
export interface CustomLoggerSinks extends Sinks {
customLogger: {
info(message: string): void;
};
}
// @@@SNIPEND
const { customLogger } = wf.proxySinks<CustomLoggerSinks>();
export async function logSinkTester(): Promise<void> {
customLogger.info(
`Workflow execution started, replaying: ${wf.workflowInfo().unsafe.isReplaying}, hl: ${
wf.workflowInfo().historyLength
}`
);
// We rely on this test to run with workflow cache disabled. This sleep()
// therefore ends the current WFT, evicting the workflow from cache, and thus
// causing replay of the first sink call.
await wf.sleep(1);
customLogger.info(
`Workflow execution completed, replaying: ${wf.workflowInfo().unsafe.isReplaying}, hl: ${
wf.workflowInfo().historyLength
}`
);
}
// eslint-disable-next-line deprecation/deprecation
const { defaultWorkerLogger } = wf.proxySinks<wf.LoggerSinks>();
export async function useDepreatedLoggerSinkWorkflow(): Promise<void> {
defaultWorkerLogger.info('Log message from workflow', { workflowId: wf.workflowInfo().workflowId });
}