This repository has been archived on 2025-11-27. You can view files and clone it, but cannot push or open issues or pull requests.
Files
page-proxy/src/module/redis/get-app-status.ts
2025-02-27 18:54:24 +08:00

31 lines
798 B
TypeScript

import { redis } from './redis.ts';
export type AppLoadStatus = {
status: 'running' | 'loading' | 'error' | 'not-exist';
message: string;
};
export const getAppLoadStatus = async (user: string, app: string): Promise<AppLoadStatus> => {
const key = 'user:app:status:' + app + ':' + user;
const value = await redis.get(key);
if (!value) {
return {
status: 'not-exist',
message: 'not-exist',
}; // 没有加载过
}
try {
return JSON.parse(value);
} catch (err) {
return {
status: 'error',
message: 'error',
};
}
};
export const setAppLoadStatus = async (user: string, app: string, status: AppLoadStatus) => {
const key = 'user:app:status:' + app + ':' + user;
const value = JSON.stringify(status);
await redis.set(key, value);
};