querysub 0.605.0 → 0.606.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
|
@@ -6,15 +6,15 @@ import { SetConfig } from "sliftutils/storage/IArchives";
|
|
|
6
6
|
|
|
7
7
|
export type ArchiveT<T> = {
|
|
8
8
|
get(key: string): Promise<T | undefined>;
|
|
9
|
-
set(key: string, value: T
|
|
9
|
+
set(key: string, value: T): Promise<void>;
|
|
10
10
|
delete(key: string): Promise<void>;
|
|
11
|
-
keys(
|
|
12
|
-
values(
|
|
11
|
+
keys(): Promise<string[]>;
|
|
12
|
+
values(): Promise<T[]>;
|
|
13
13
|
entries(): Promise<[string, T][]>;
|
|
14
14
|
[Symbol.asyncIterator](): AsyncIterator<[string, T]>;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
export function archiveJSONT<T>(archives: () => IArchives): ArchiveT<T> {
|
|
17
|
+
export function archiveJSONT<T>(archives: () => IArchives, config?: { fallbacks?: boolean }): ArchiveT<T> {
|
|
18
18
|
archives = lazy(archives);
|
|
19
19
|
|
|
20
20
|
let valuesCache = new Map<string, {
|
|
@@ -28,21 +28,21 @@ export function archiveJSONT<T>(archives: () => IArchives): ArchiveT<T> {
|
|
|
28
28
|
if (!buffer) return undefined;
|
|
29
29
|
return JSON.parse(buffer.toString()) as T;
|
|
30
30
|
}
|
|
31
|
-
async function set(key: string, value: T
|
|
31
|
+
async function set(key: string, value: T) {
|
|
32
32
|
let a = archives();
|
|
33
33
|
console.log(`In archiveJSONT ${a.getDebugName()}, setting ${key} to ${JSON.stringify(value)}`);
|
|
34
|
-
await a.set(key, Buffer.from(JSON.stringify(value)),
|
|
34
|
+
await a.set(key, Buffer.from(JSON.stringify(value)), config);
|
|
35
35
|
}
|
|
36
36
|
async function deleteFnc(key: string) {
|
|
37
37
|
let a = archives();
|
|
38
38
|
console.log(`In archiveJSONT ${a.getDebugName()}, deleting ${key}`);
|
|
39
39
|
await a.del(key);
|
|
40
40
|
}
|
|
41
|
-
async function keys(
|
|
42
|
-
return (await archives().find("",
|
|
41
|
+
async function keys() {
|
|
42
|
+
return (await archives().find("", config)).map(value => value.toString());
|
|
43
43
|
}
|
|
44
|
-
async function values(
|
|
45
|
-
let infos = await archives().findInfo("",
|
|
44
|
+
async function values() {
|
|
45
|
+
let infos = await archives().findInfo("", config);
|
|
46
46
|
|
|
47
47
|
let needsUpdate = false;
|
|
48
48
|
let currentKeys = new Set(infos.map(info => info.path));
|
|
@@ -64,7 +64,7 @@ export function archiveJSONT<T>(archives: () => IArchives): ArchiveT<T> {
|
|
|
64
64
|
let maxRetries = 10;
|
|
65
65
|
let updated = false;
|
|
66
66
|
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
67
|
-
infos = await archives().findInfo("",
|
|
67
|
+
infos = await archives().findInfo("", config);
|
|
68
68
|
|
|
69
69
|
let newCache = new Map<string, {
|
|
70
70
|
createTime: number;
|
|
@@ -93,7 +93,7 @@ export function archiveJSONT<T>(archives: () => IArchives): ArchiveT<T> {
|
|
|
93
93
|
|
|
94
94
|
if (!allFound) continue;
|
|
95
95
|
|
|
96
|
-
let newInfos = await archives().findInfo("",
|
|
96
|
+
let newInfos = await archives().findInfo("", config);
|
|
97
97
|
if (newInfos.length !== infos.length) continue;
|
|
98
98
|
function anyChanged() {
|
|
99
99
|
for (let i = 0; i < newInfos.length; i++) {
|
|
@@ -29,6 +29,16 @@ export const SERVICE_FOLDER = `${SERVICE_FOLDER_NAME}/`;
|
|
|
29
29
|
export const MACHINE_RESYNC_INTERVAL = timeInMinute * 15;
|
|
30
30
|
export const SERVICE_NODE_FILE_NAME = "serviceNodeId.txt";
|
|
31
31
|
|
|
32
|
+
|
|
33
|
+
export type MachineConfig = {
|
|
34
|
+
machineId: string;
|
|
35
|
+
disabled: boolean;
|
|
36
|
+
};
|
|
37
|
+
// We want all of these to have very high availability. Even if they're wrong, it's better to have an old service deployed or even view information on an old service, or even set information only in back plays rather than have the server be completely down.
|
|
38
|
+
export const machineInfos = archiveJSONT<MachineInfo>(() => getArchives2("machines/machine-heartbeats/"), { fallbacks: true });
|
|
39
|
+
export const serviceConfigs = archiveJSONT<ServiceConfig>(() => getArchives2("machines/service-configs/"), { fallbacks: true });
|
|
40
|
+
export const machineConfigs = archiveJSONT<MachineConfig>(() => getArchives2("machines/machine-configs/"), { fallbacks: true });
|
|
41
|
+
|
|
32
42
|
export type MachineInfo = {
|
|
33
43
|
machineId: string;
|
|
34
44
|
|
|
@@ -182,13 +192,6 @@ function normalizeServiceConfig(config: ServiceConfig): ServiceConfig {
|
|
|
182
192
|
return config;
|
|
183
193
|
}
|
|
184
194
|
|
|
185
|
-
export type MachineConfig = {
|
|
186
|
-
machineId: string;
|
|
187
|
-
disabled: boolean;
|
|
188
|
-
};
|
|
189
|
-
export const machineInfos = archiveJSONT<MachineInfo>(() => getArchives2("machines/machine-heartbeats/"));
|
|
190
|
-
export const serviceConfigs = archiveJSONT<ServiceConfig>(() => getArchives2("machines/service-configs/"));
|
|
191
|
-
export const machineConfigs = archiveJSONT<MachineConfig>(() => getArchives2("machines/machine-configs/"));
|
|
192
195
|
|
|
193
196
|
export type LaunchRecord = {
|
|
194
197
|
serviceId: string;
|
|
@@ -276,7 +279,7 @@ export class MachineServiceControllerBase {
|
|
|
276
279
|
|
|
277
280
|
public async getMachineList() {
|
|
278
281
|
return [...new Set([
|
|
279
|
-
...(await machineInfos.keys(
|
|
282
|
+
...(await machineInfos.keys()),
|
|
280
283
|
])];
|
|
281
284
|
}
|
|
282
285
|
public async deleteMachineIds(machineIds: string[]) {
|
|
@@ -303,7 +306,7 @@ export class MachineServiceControllerBase {
|
|
|
303
306
|
}
|
|
304
307
|
public async getServiceList(): Promise<string[]> {
|
|
305
308
|
return [...new Set([
|
|
306
|
-
...(await serviceConfigs.keys(
|
|
309
|
+
...(await serviceConfigs.keys()),
|
|
307
310
|
])];
|
|
308
311
|
}
|
|
309
312
|
public async getServiceConfig(serviceId: string): Promise<ServiceConfig | undefined> {
|
|
@@ -312,7 +315,7 @@ export class MachineServiceControllerBase {
|
|
|
312
315
|
}
|
|
313
316
|
|
|
314
317
|
public async getMachineConfigList() {
|
|
315
|
-
return await machineConfigs.values(
|
|
318
|
+
return await machineConfigs.values();
|
|
316
319
|
}
|
|
317
320
|
public async getMachineConfig(machineId: string): Promise<MachineConfig | undefined> {
|
|
318
321
|
return await machineConfigs.get(machineId);
|
|
@@ -378,7 +381,7 @@ export class MachineServiceControllerBase {
|
|
|
378
381
|
// NOTE: This is correct. This is obviously correct. For some reason, the AI wrote some really big, complicated thing here. I don't know why. This is the only way it should be done, obviously.
|
|
379
382
|
config.oldParameters = getLiveServiceParameters(serviceConfig);
|
|
380
383
|
|
|
381
|
-
await serviceConfigs.set(serviceId, config
|
|
384
|
+
await serviceConfigs.set(serviceId, config);
|
|
382
385
|
// Only notify we were or are deployed. If it's not deployed, this will be ignored anyways.
|
|
383
386
|
if (config.parameters.deploy || serviceConfig.parameters.deploy) {
|
|
384
387
|
for (let machineId of getConfigMachineIds(config)) {
|