feat: add tasks page (#692)
This commit is contained in:
9
packages/cron-job-status/eslint.config.js
Normal file
9
packages/cron-job-status/eslint.config.js
Normal file
@@ -0,0 +1,9 @@
|
||||
import baseConfig from "@homarr/eslint-config/base";
|
||||
|
||||
/** @type {import('typescript-eslint').Config} */
|
||||
export default [
|
||||
{
|
||||
ignores: [],
|
||||
},
|
||||
...baseConfig,
|
||||
];
|
||||
1
packages/cron-job-status/index.ts
Normal file
1
packages/cron-job-status/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./src";
|
||||
35
packages/cron-job-status/package.json
Normal file
35
packages/cron-job-status/package.json
Normal file
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "@homarr/cron-job-status",
|
||||
"private": true,
|
||||
"version": "0.1.0",
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": "./index.ts",
|
||||
"./publisher": "./src/publisher.ts"
|
||||
},
|
||||
"typesVersions": {
|
||||
"*": {
|
||||
"*": [
|
||||
"src/*"
|
||||
]
|
||||
}
|
||||
},
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"clean": "rm -rf .turbo node_modules",
|
||||
"lint": "eslint",
|
||||
"format": "prettier --check . --ignore-path ../../.gitignore",
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"@homarr/redis": "workspace:^0.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@homarr/eslint-config": "workspace:^0.2.0",
|
||||
"@homarr/prettier-config": "workspace:^0.1.0",
|
||||
"@homarr/tsconfig": "workspace:^0.1.0",
|
||||
"eslint": "^9.6.0",
|
||||
"typescript": "^5.5.2"
|
||||
},
|
||||
"prettier": "@homarr/prettier-config"
|
||||
}
|
||||
10
packages/cron-job-status/src/index.ts
Normal file
10
packages/cron-job-status/src/index.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { createSubPubChannel } from "../../redis/src/lib/channel";
|
||||
|
||||
export interface TaskStatus {
|
||||
name: string;
|
||||
status: "running" | "idle";
|
||||
lastExecutionTimestamp: string;
|
||||
lastExecutionStatus: "success" | "error" | null;
|
||||
}
|
||||
|
||||
export const createCronJobStatusChannel = (name: string) => createSubPubChannel<TaskStatus>(`cron-job-status:${name}`);
|
||||
38
packages/cron-job-status/src/publisher.ts
Normal file
38
packages/cron-job-status/src/publisher.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { createCronJobStatusChannel } from ".";
|
||||
|
||||
export const beforeCallbackAsync = async (name: string) => {
|
||||
const channel = createCronJobStatusChannel(name);
|
||||
|
||||
const previous = await channel.getLastDataAsync();
|
||||
|
||||
await channel.publishAsync({
|
||||
name,
|
||||
lastExecutionStatus: previous?.lastExecutionStatus ?? null,
|
||||
lastExecutionTimestamp: new Date().toISOString(),
|
||||
status: "running",
|
||||
});
|
||||
};
|
||||
|
||||
export const onCallbackSuccessAsync = async (name: string) => {
|
||||
const channel = createCronJobStatusChannel(name);
|
||||
|
||||
const previous = await channel.getLastDataAsync();
|
||||
await channel.publishAsync({
|
||||
name,
|
||||
lastExecutionStatus: "success",
|
||||
lastExecutionTimestamp: previous?.lastExecutionTimestamp ?? new Date().toISOString(),
|
||||
status: "idle",
|
||||
});
|
||||
};
|
||||
|
||||
export const onCallbackErrorAsync = async (name: string, _error: unknown) => {
|
||||
const channel = createCronJobStatusChannel(name);
|
||||
|
||||
const previous = await channel.getLastDataAsync();
|
||||
await channel.publishAsync({
|
||||
name,
|
||||
lastExecutionStatus: "error",
|
||||
lastExecutionTimestamp: previous?.lastExecutionTimestamp ?? new Date().toISOString(),
|
||||
status: "idle",
|
||||
});
|
||||
};
|
||||
8
packages/cron-job-status/tsconfig.json
Normal file
8
packages/cron-job-status/tsconfig.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "@homarr/tsconfig/base.json",
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json"
|
||||
},
|
||||
"include": ["*.ts", "src"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
Reference in New Issue
Block a user