-
Notifications
You must be signed in to change notification settings - Fork 6
/
events.ts
43 lines (37 loc) · 903 Bytes
/
events.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
import { uuid } from "../utils/uuid";
export enum TaskDispatcherEvent {
TaskExecutionStarted = "taskExecutionStarted",
TaskExecutionTimedOut = "taskExecutionTimedOut",
TaskChainFinished = "taskChainFinished",
DefaultCancelEvent = "defaultCancelEvent",
}
export interface DispatchableEvent {
name: string;
id: string;
expirationTimestamp: number;
data: EventData;
}
export interface EventData {
[key: string]: any;
}
export function createEvent(
name: string,
params: CreateEventParams = {}
): DispatchableEvent {
const id = params.id ? params.id : uuid();
const data = params.data ? params.data : {};
const expirationTimestamp = params.expirationTimestamp
? params.expirationTimestamp
: -1;
return {
name,
id,
expirationTimestamp,
data,
};
}
interface CreateEventParams {
data?: EventData;
id?: string;
expirationTimestamp?: number;
}