mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-18 23:33:12 +09:00
Add typing for serialized collector type
Setup TypeScript tyings and JSON schema for serializeResult and deserializeResult and use these in the metrics related requests.
This commit is contained in:
1 parent
b66138587b
commit
b78ca31b09
7 files changed
+46
-26
No files matched your search
@@ -542,7 +542,7 @@ export default class Host extends lib.Link {
|
||||
}
|
||||
|
||||
async handleHostMetricsRequest() {
|
||||
let requests = [];
|
||||
let requests: Promise<InstanceType<typeof lib.InstanceMetricsRequest["Response"]>>[] = [];
|
||||
for (let instanceConnection of this.instanceConnections.values()) {
|
||||
requests.push(instanceConnection.send(new lib.InstanceMetricsRequest()));
|
||||
}
|
||||
|
||||
@@ -962,11 +962,12 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " ");
|
||||
}
|
||||
|
||||
async handleInstanceMetricsRequest() {
|
||||
let results = [];
|
||||
let results: ReturnType<typeof lib.serializeResult>[] = [];
|
||||
if (!["stopped", "stopping"].includes(this._status)) {
|
||||
let pluginResults = await lib.invokeHook(this.plugins, "onMetrics");
|
||||
type ResultIterator = AsyncIterable<lib.CollectorResult> | Iterable<lib.CollectorResult>
|
||||
let pluginResults = await lib.invokeHook(this.plugins, "onMetrics") as ResultIterator[];
|
||||
for (let metricIterator of pluginResults) {
|
||||
for await (let metric of metricIterator as any) {
|
||||
for await (let metric of metricIterator) {
|
||||
results.push(lib.serializeResult(metric));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user