anbaric-tsapi 1.12.0 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/src/api/jobs/Job.ts
CHANGED
|
@@ -9,10 +9,11 @@ class Job {
|
|
|
9
9
|
readonly startedAt : Date;
|
|
10
10
|
readonly startedBy : string;
|
|
11
11
|
readonly lastUpdated : Date;
|
|
12
|
+
readonly killed : boolean;
|
|
12
13
|
|
|
13
14
|
constructor(id : string, properties : Map<string, any> = new Map(), state: string, workflowId? : string,
|
|
14
15
|
startedBy : string = "system", startedAt : Date = new Date(),
|
|
15
|
-
lastUpdated : Date = startedAt) {
|
|
16
|
+
lastUpdated : Date = startedAt, killed : boolean = false) {
|
|
16
17
|
|
|
17
18
|
this.id = id;
|
|
18
19
|
this.properties = properties;
|
|
@@ -21,6 +22,7 @@ class Job {
|
|
|
21
22
|
this.startedBy = startedBy;
|
|
22
23
|
this.startedAt = startedAt;
|
|
23
24
|
this.lastUpdated = lastUpdated;
|
|
25
|
+
this.killed = killed;
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
}
|
|
@@ -42,12 +42,29 @@ abstract class JobPersistence {
|
|
|
42
42
|
job.workflowId,
|
|
43
43
|
job.startedBy,
|
|
44
44
|
job.startedAt,
|
|
45
|
-
new Date()
|
|
45
|
+
new Date(),
|
|
46
|
+
job.killed
|
|
46
47
|
)
|
|
47
48
|
|
|
48
49
|
this.saveInternal(updatedJob);
|
|
49
50
|
}
|
|
50
51
|
|
|
52
|
+
async kill(id : string, actor : Actor) : Promise<void> {
|
|
53
|
+
await this.auditor.audit("job", id, actor, [JobPersistence.Interaction.KILL], "Job killed", null);
|
|
54
|
+
await this.killInternal(id);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async killOlderThan(lastUpdatedBefore : Date, actor : Actor) : Promise<number> {
|
|
58
|
+
await this.auditor.audit("job", "*", actor, [JobPersistence.Interaction.KILL],
|
|
59
|
+
`Jobs not updated since ${lastUpdatedBefore.toISOString()} killed`, null);
|
|
60
|
+
return this.killOlderThanInternal(lastUpdatedBefore);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async countByState(actor : Actor) : Promise<Array<JobPersistence.StateCount>> {
|
|
64
|
+
await this.auditor.audit("job", "*", actor, [JobPersistence.Interaction.LIST], "", null);
|
|
65
|
+
return this.countByStateInternal();
|
|
66
|
+
}
|
|
67
|
+
|
|
51
68
|
private generatePropertiesDiff(oldVersion : Map<string, any>, newVersion : Map<string, any>) : Map<string, {from: any, to: any}> {
|
|
52
69
|
const diff: Map<string, { from: any; to: any; }> = new Map();
|
|
53
70
|
|
|
@@ -84,6 +101,9 @@ abstract class JobPersistence {
|
|
|
84
101
|
protected abstract retrieveInternal(id : string) : Promise<Job>;
|
|
85
102
|
protected abstract deleteInternal(id : string) : Promise<void>;
|
|
86
103
|
protected abstract listInternal(pageSize? : number, page? : number) : Promise<Array<Job>>;
|
|
104
|
+
protected abstract killInternal(id : string) : Promise<void>;
|
|
105
|
+
protected abstract killOlderThanInternal(lastUpdatedBefore : Date) : Promise<number>;
|
|
106
|
+
protected abstract countByStateInternal() : Promise<Array<JobPersistence.StateCount>>;
|
|
87
107
|
|
|
88
108
|
}
|
|
89
109
|
|
|
@@ -96,8 +116,15 @@ namespace JobPersistence {
|
|
|
96
116
|
DELETE = "DELETE",
|
|
97
117
|
READ = "READ",
|
|
98
118
|
LIST = "LIST",
|
|
119
|
+
KILL = "KILL",
|
|
99
120
|
}
|
|
100
121
|
|
|
122
|
+
export type StateCount = {
|
|
123
|
+
state : string,
|
|
124
|
+
killed : boolean,
|
|
125
|
+
count : number,
|
|
126
|
+
};
|
|
127
|
+
|
|
101
128
|
}
|
|
102
129
|
|
|
103
130
|
export { JobPersistence }
|
|
@@ -8,6 +8,7 @@ type SerializedJob = {
|
|
|
8
8
|
startedAt? : string,
|
|
9
9
|
startedBy? : string,
|
|
10
10
|
lastUpdated? : string,
|
|
11
|
+
killed? : boolean,
|
|
11
12
|
};
|
|
12
13
|
|
|
13
14
|
const serializeJob = (job : Job) : SerializedJob => ({
|
|
@@ -18,13 +19,14 @@ const serializeJob = (job : Job) : SerializedJob => ({
|
|
|
18
19
|
startedAt: job.startedAt.toISOString(),
|
|
19
20
|
startedBy: job.startedBy,
|
|
20
21
|
lastUpdated: job.lastUpdated.toISOString(),
|
|
22
|
+
killed: job.killed,
|
|
21
23
|
});
|
|
22
24
|
|
|
23
25
|
const deserializeJob = (serialized : SerializedJob) : Job => {
|
|
24
26
|
const startedAt = serialized.startedAt ? new Date(serialized.startedAt) : new Date();
|
|
25
27
|
return new Job(serialized.id, new Map(Object.entries(serialized.properties)), serialized.state,
|
|
26
28
|
serialized.workflowId, serialized.startedBy ?? "system", startedAt,
|
|
27
|
-
serialized.lastUpdated ? new Date(serialized.lastUpdated) : startedAt);
|
|
29
|
+
serialized.lastUpdated ? new Date(serialized.lastUpdated) : startedAt, serialized.killed ?? false);
|
|
28
30
|
};
|
|
29
31
|
|
|
30
32
|
export { serializeJob, deserializeJob };
|