feat: Implement Cloudly Task Manager with predefined tasks and execution tracking
- Added CloudlyTaskManager class for managing tasks, including registration, execution, scheduling, and cancellation. - Created predefined tasks: DNS Sync, Certificate Renewal, Cleanup, Health Check, Resource Report, Database Maintenance, Security Scan, and Docker Cleanup. - Introduced ITaskExecution interface for tracking task execution details and outcomes. - Developed API request interfaces for task management operations (getTasks, getTaskExecutions, triggerTask, cancelTask). - Implemented CloudlyViewTasks web component for displaying tasks and their execution history, including filtering and detailed views.
This commit is contained in:
@@ -15,6 +15,7 @@ export * from './clusternode.js';
|
||||
export * from './settings.js';
|
||||
export * from './service.js';
|
||||
export * from './status.js';
|
||||
export * from './taskexecution.js';
|
||||
export * from './traffic.js';
|
||||
export * from './user.js';
|
||||
export * from './version.js';
|
||||
|
84
ts_interfaces/data/taskexecution.ts
Normal file
84
ts_interfaces/data/taskexecution.ts
Normal file
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* Task execution tracking for the task management system
|
||||
* Tasks themselves are hard-coded using @push.rocks/taskbuffer
|
||||
* This interface tracks execution history and outcomes
|
||||
*/
|
||||
export interface ITaskExecution {
|
||||
id: string;
|
||||
data: {
|
||||
/**
|
||||
* Name of the task being executed
|
||||
*/
|
||||
taskName: string;
|
||||
|
||||
/**
|
||||
* Optional description of what the task does
|
||||
*/
|
||||
taskDescription?: string;
|
||||
|
||||
/**
|
||||
* Category for grouping tasks
|
||||
*/
|
||||
category?: 'maintenance' | 'deployment' | 'backup' | 'monitoring' | 'cleanup' | 'system' | 'security';
|
||||
|
||||
/**
|
||||
* Timestamp when the task started
|
||||
*/
|
||||
startedAt: number;
|
||||
|
||||
/**
|
||||
* Timestamp when the task completed
|
||||
*/
|
||||
completedAt?: number;
|
||||
|
||||
/**
|
||||
* Current status of the task execution
|
||||
*/
|
||||
status: 'running' | 'completed' | 'failed' | 'cancelled';
|
||||
|
||||
/**
|
||||
* Duration in milliseconds
|
||||
*/
|
||||
duration?: number;
|
||||
|
||||
/**
|
||||
* How the task was triggered
|
||||
*/
|
||||
triggeredBy: 'schedule' | 'manual' | 'system';
|
||||
|
||||
/**
|
||||
* User ID if manually triggered
|
||||
*/
|
||||
userId?: string;
|
||||
|
||||
/**
|
||||
* Execution logs
|
||||
*/
|
||||
logs: Array<{
|
||||
timestamp: number;
|
||||
message: string;
|
||||
severity: 'info' | 'warning' | 'error' | 'success';
|
||||
}>;
|
||||
|
||||
/**
|
||||
* Task-specific metrics
|
||||
*/
|
||||
metrics?: {
|
||||
[key: string]: any;
|
||||
};
|
||||
|
||||
/**
|
||||
* Final result/output of the task
|
||||
*/
|
||||
result?: any;
|
||||
|
||||
/**
|
||||
* Error details if the task failed
|
||||
*/
|
||||
error?: {
|
||||
message: string;
|
||||
stack?: string;
|
||||
code?: string;
|
||||
};
|
||||
};
|
||||
}
|
@@ -22,6 +22,7 @@ import * as serverRequests from './server.js';
|
||||
import * as serviceRequests from './service.js';
|
||||
import * as settingsRequests from './settings.js';
|
||||
import * as statusRequests from './status.js';
|
||||
import * as taskRequests from './task.js';
|
||||
import * as versionRequests from './version.js';
|
||||
|
||||
export {
|
||||
@@ -47,6 +48,7 @@ export {
|
||||
serviceRequests as service,
|
||||
settingsRequests as settings,
|
||||
statusRequests as status,
|
||||
taskRequests as task,
|
||||
versionRequests as version,
|
||||
};
|
||||
|
||||
|
88
ts_interfaces/requests/task.ts
Normal file
88
ts_interfaces/requests/task.ts
Normal file
@@ -0,0 +1,88 @@
|
||||
import * as plugins from '../plugins.js';
|
||||
import * as data from '../data/index.js';
|
||||
|
||||
// Get all tasks
|
||||
export interface IRequest_Any_Cloudly_GetTasks
|
||||
extends plugins.typedrequestInterfaces.implementsTR<
|
||||
plugins.typedrequestInterfaces.ITypedRequest,
|
||||
IRequest_Any_Cloudly_GetTasks
|
||||
> {
|
||||
method: 'getTasks';
|
||||
request: {};
|
||||
response: {
|
||||
tasks: Array<{
|
||||
name: string;
|
||||
description: string;
|
||||
category: 'maintenance' | 'deployment' | 'backup' | 'monitoring' | 'cleanup' | 'system' | 'security';
|
||||
schedule?: string;
|
||||
lastRun?: number;
|
||||
enabled: boolean;
|
||||
}>;
|
||||
};
|
||||
}
|
||||
|
||||
// Get task executions
|
||||
export interface IRequest_Any_Cloudly_GetTaskExecutions
|
||||
extends plugins.typedrequestInterfaces.implementsTR<
|
||||
plugins.typedrequestInterfaces.ITypedRequest,
|
||||
IRequest_Any_Cloudly_GetTaskExecutions
|
||||
> {
|
||||
method: 'getTaskExecutions';
|
||||
request: {
|
||||
filter?: {
|
||||
taskName?: string;
|
||||
status?: string;
|
||||
startedAfter?: number;
|
||||
startedBefore?: number;
|
||||
};
|
||||
};
|
||||
response: {
|
||||
executions: data.ITaskExecution[];
|
||||
};
|
||||
}
|
||||
|
||||
// Get task execution by ID
|
||||
export interface IRequest_Any_Cloudly_GetTaskExecutionById
|
||||
extends plugins.typedrequestInterfaces.implementsTR<
|
||||
plugins.typedrequestInterfaces.ITypedRequest,
|
||||
IRequest_Any_Cloudly_GetTaskExecutionById
|
||||
> {
|
||||
method: 'getTaskExecutionById';
|
||||
request: {
|
||||
executionId: string;
|
||||
};
|
||||
response: {
|
||||
execution: data.ITaskExecution;
|
||||
};
|
||||
}
|
||||
|
||||
// Trigger task manually
|
||||
export interface IRequest_Any_Cloudly_TriggerTask
|
||||
extends plugins.typedrequestInterfaces.implementsTR<
|
||||
plugins.typedrequestInterfaces.ITypedRequest,
|
||||
IRequest_Any_Cloudly_TriggerTask
|
||||
> {
|
||||
method: 'triggerTask';
|
||||
request: {
|
||||
taskName: string;
|
||||
userId?: string;
|
||||
};
|
||||
response: {
|
||||
execution: data.ITaskExecution;
|
||||
};
|
||||
}
|
||||
|
||||
// Cancel a running task
|
||||
export interface IRequest_Any_Cloudly_CancelTask
|
||||
extends plugins.typedrequestInterfaces.implementsTR<
|
||||
plugins.typedrequestInterfaces.ITypedRequest,
|
||||
IRequest_Any_Cloudly_CancelTask
|
||||
> {
|
||||
method: 'cancelTask';
|
||||
request: {
|
||||
executionId: string;
|
||||
};
|
||||
response: {
|
||||
success: boolean;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user