/
Scheduler.ts
92 lines (81 loc) · 2.64 KB
/
Scheduler.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
import { QlikRepositoryClient } from "qlik-rest-api";
import { IUpdateObjectOptions } from "./types/interfaces";
import { IHttpStatus } from "./types/ranges";
import { ISchedulerService, ISchedulerServiceUpdate } from "./types/interfaces";
import { UpdateCommonProperties } from "./util/UpdateCommonProps";
export interface IClassScheduler {
remove(): Promise<IHttpStatus>;
update(
arg: ISchedulerServiceUpdate,
options?: IUpdateObjectOptions
): Promise<ISchedulerService>;
details: ISchedulerService;
}
export class Scheduler implements IClassScheduler {
#id: string;
#repoClient: QlikRepositoryClient;
details: ISchedulerService;
constructor(
repoClient: QlikRepositoryClient,
id: string,
details?: ISchedulerService
) {
if (!id)
throw new Error(`schedulerservice.get: "id" parameter is required`);
this.#id = id;
this.#repoClient = repoClient;
if (details) this.details = details;
}
async init() {
if (!this.details) {
this.details = await this.#repoClient
.Get<ISchedulerService>(`schedulerservice/${this.#id}`)
.then((res) => res.data);
}
}
public async remove() {
return await this.#repoClient
.Delete(`schedulerservice/${this.#id}`)
.then((res) => res.status);
}
public async update(
arg: ISchedulerServiceUpdate,
options?: IUpdateObjectOptions
) {
if (arg.schedulerServiceType) {
if (arg.schedulerServiceType == "Master")
this.details.settings.schedulerServiceType = 0;
if (arg.schedulerServiceType == "Slave")
this.details.settings.schedulerServiceType = 1;
if (arg.schedulerServiceType == "MasterAndSlave")
this.details.settings.schedulerServiceType = 2;
}
if (arg.maxConcurrentEngines) {
if (arg.maxConcurrentEngines < 1 && arg.maxConcurrentEngines > 256)
throw new Error(
`scheduler.update: "maxConcurrentEngines" value must be between 1 and 256`
);
this.details.settings.maxConcurrentEngines = arg.maxConcurrentEngines;
}
if (arg.engineTimeout) {
if (arg.engineTimeout < 10 && arg.engineTimeout > 10080)
throw new Error(
`scheduler.update: "engineTimeout" value must be between 10 and 10080`
);
this.details.settings.engineTimeout = arg.engineTimeout;
}
let updateCommon = new UpdateCommonProperties(
this.#repoClient,
this.details,
arg,
options
);
this.details = await updateCommon.updateAll();
return await this.#repoClient
.Put<ISchedulerService>(
`schedulerservice/${this.details.id}`,
this.details
)
.then((res) => res.data);
}
}