1
0
Fork 0

feat(gui): batch status requests (#238)

This commit is contained in:
Sean Sube 2024-01-14 08:22:37 -06:00
parent 150ed7564d
commit d349e8cc10
Signed by: ssube
GPG Key ID: 3EED7B957D362AF1
3 changed files with 29 additions and 2 deletions

View File

@ -16,6 +16,7 @@
"@tanstack/react-query": "^4.0.5",
"@types/lodash": "^4.14.192",
"@types/node": "^18.15.11",
"@yornaath/batshit": "^0.9.0",
"allotment": "^1.19.5",
"browser-bunyan": "^1.8.0",
"exifreader": "^4.13.0",

View File

@ -1,8 +1,9 @@
/* eslint-disable max-lines */
import { doesExist, InvalidArgumentError, Maybe } from '@apextoaster/js-utils';
import { create as batcher, windowScheduler, keyResolver } from '@yornaath/batshit';
import { ServerParams } from '../config.js';
import { FIXED_FLOAT, FIXED_INTEGER, STATUS_SUCCESS } from '../constants.js';
import { FIXED_FLOAT, FIXED_INTEGER, POLL_TIME, STATUS_SUCCESS } from '../constants.js';
import { JobResponse, JobResponseWithRetry, SuccessJobResponse } from '../types/api-v2.js';
import {
FilterResponse,
@ -129,7 +130,7 @@ export function makeClient(root: string, token: Maybe<string> = undefined, f = f
return f(url, options).then((res) => parseJobResponse(root, res));
}
return {
const client = {
async extras(): Promise<ExtrasFile> {
const path = makeApiUrl(root, 'extras');
@ -500,6 +501,19 @@ export function makeClient(root: string, token: Maybe<string> = undefined, f = f
return new URL(joinPath('output', image.outputs[index]), root).toString();
},
};
const batchStatus = batcher({
fetcher: async (jobs: Array<string>) => client.status(jobs),
resolver: keyResolver('name'),
scheduler: windowScheduler(POLL_TIME),
});
return {
...client,
async status(keys): Promise<Array<JobResponse>> {
return Promise.all(keys.map((key) => batchStatus.fetch(key)));
},
};
}
/**

View File

@ -791,6 +791,18 @@
resolved "https://registry.yarnpkg.com/@xobotyi/scrollbar-width/-/scrollbar-width-1.9.5.tgz#80224a6919272f405b87913ca13b92929bdf3c4d"
integrity sha512-N8tkAACJx2ww8vFMneJmaAgmjAG1tnVBZJRLRcx061tmsLRZHSEZSLuGWnwPtunsSLvSqXQ2wfp7Mgqg1I+2dQ==
"@yornaath/batshit-devtools@^1.6.0":
version "1.6.0"
resolved "https://registry.yarnpkg.com/@yornaath/batshit-devtools/-/batshit-devtools-1.6.0.tgz#a40de72569d9571e4fcf3be9ea623f54203e7c99"
integrity sha512-ckKxrdfuFSRFz54tYU+VkD1eZOOaxa92U4eKOPtlxc1itB12Cqb1Dmk8Rqv6mARxp8YvocVGKbccrXoCwH2Lew==
"@yornaath/batshit@^0.9.0":
version "0.9.0"
resolved "https://registry.yarnpkg.com/@yornaath/batshit/-/batshit-0.9.0.tgz#4d078e6ed3cadb5d8c4ae762363f40b6f61ad7d0"
integrity sha512-QdI1hQUPlpFT+o1iKLi9fQEKCli8c3UG7q4Ih8MP4jn+pyAjbfC4xaK5PwqSsSZgT0YeAZ0GWbbO9+1xAtWXlQ==
dependencies:
"@yornaath/batshit-devtools" "^1.6.0"
acorn-jsx@^5.3.2:
version "5.3.2"
resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-5.3.2.tgz#7ed5bb55908b3b2f1bc55c6af1653bada7f07937"