Implement app start/stop and add app state polling for the moment

This commit is contained in:
Johannes Zellner
2025-02-21 12:20:23 +01:00
parent 8132920ed8
commit 6a5de6606c
4 changed files with 78 additions and 23 deletions
+16 -1
View File
@@ -1,11 +1,26 @@
import { fetcher } from 'pankow';
import { sleep } from 'pankow/utils';
function create() {
const accessToken = localStorage.token;
const origin = import.meta.env.VITE_API_ORIGIN || window.location.origin;
return {
async wait(id) {
while(true) {
let result;
try {
result = await fetcher.get(`${origin}/api/v1/tasks/${id}`, { access_token: accessToken });
} catch (e) {
return [e];
}
if (!result.body.active) return [result.body.error, result.body.result];
await sleep(2000);
}
},
async getLatestByType(type) {
let error, result;
try {
@@ -49,7 +64,7 @@ function create() {
if (error || result.status !== 204) return [error || result];
return [null];
}
},
};
}