/
DiProjectTask.ts
93 lines (85 loc) · 2.12 KB
/
DiProjectTask.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { QlikSaaSClient } from "qlik-rest-api";
export interface IDiProjectTask {
id: string;
name: string;
type:
| "LANDING"
| "STORAGE"
| "QVD_STORAGE"
| "TRANSFORM"
| "DATAMART"
| "REGISTERED_DATA"
| "REPLICATION"
| "DISTRIBUTION"
| "LAKE_LANDING"
| string;
ownerId: string;
spaceId: string;
description: string;
}
export interface IDataTaskInstanceState {
lastRun: {
state: "STARTING" | "RUNNING" | "COMPLETED" | "FAILED" | "CANCELED";
message: string;
};
runReadiness: {
state: "READY_TO_RUN" | "ALREADY_RUNNING" | "NOT_RUNNABLE";
message: string;
};
}
export class DiProjectTask {
#id: string;
#projectId: string;
#saasClient: QlikSaaSClient;
details: IDiProjectTask;
constructor(
saasClient: QlikSaaSClient,
id: string,
projectId: string,
details?: IDiProjectTask
) {
if (!id) throw new Error(`diProjectTask.get: "id" parameter is required`);
if (!projectId)
throw new Error(`diProjectTask.projectId: "id" parameter is required`);
this.details = details ?? ({} as IDiProjectTask);
this.#id = id;
this.#projectId = projectId;
this.#saasClient = saasClient;
}
async init(arg?: { force: boolean }) {
if (
!this.details ||
Object.keys(this.details).length == 0 ||
arg?.force == true
) {
this.details = await this.#saasClient
.Get<IDiProjectTask>(
`di-projects/${this.#projectId}/di-tasks/${this.#id}`
)
.then((res) => res.data);
}
}
async start() {
return await this.#saasClient
.Post<IDiProjectTask>(
`di-projects/${this.#projectId}/di-tasks/${this.#id}/start`,
{}
)
.then((res) => res.status);
}
async stop() {
return await this.#saasClient
.Post<IDiProjectTask>(
`di-projects/${this.#projectId}/di-tasks/${this.#id}/stop`,
{}
)
.then((res) => res.status);
}
async state() {
return await this.#saasClient
.Get<IDataTaskInstanceState>(
`di-projects/${this.#projectId}/di-tasks/${this.#id}/state`
)
.then((res) => res.data);
}
}