Task Engine

Provides an engine for executing and monitoring tasks

Technology

The task module provides a comprehensive task execution engine for Project Forge applications. It enables registration, execution, and monitoring of background tasks with real-time progress tracking and a rich web interface.

Overview

This module provides:

Key Features

Task Management

Execution Engine

Real-time Monitoring

Web Interface

Package Structure

Core Components

UI Components

Usage Examples

Registering a Task

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// Register a simple task
taskService.Register("backup", &task.Task{
Title: "Database Backup",
Description: "Creates a backup of the application database",
Category: "maintenance",
Icon: "database",
Fields: field.Fields{
field.NewField("format", "", "backup format", field.Select, field.Options{
"sql": "SQL Dump",
"tar": "Compressed Archive",
}),
},
Fn: func(ctx context.Context, logger util.Logger, ps *cutil.PageState, args map[string]any) (any, error) {
format := args["format"].(string)
// Perform backup logic
return map[string]any{"file": "backup.sql", "size": 1024000}, nil
},
})

Executing Tasks

Synchronous execution:

result, err := taskService.Run(ctx, "backup", args, logger, ps)

Asynchronous execution with progress:

1
2
run, err := taskService.Start(ctx, "backup", args, logger, ps)
// Monitor progress via run.Status() and run.Progress()

Task Parameters

Tasks support various parameter types: - Text fields: String input with validation - Select fields: Dropdown choices with predefined options - Boolean flags: Checkbox inputs for feature toggles - File uploads: File selection for data processing tasks

Configuration

The task module supports configuration through environment variables:

Execution Control

Performance Tuning

Dependencies

This module requires:

Integration Points

Service Registration

The task service is automatically registered with the application’s service container and available via dependency injection.

Web Routes

WebSocket Endpoints

Advanced Features

Custom Task Categories

Organize tasks by category for better navigation: - maintenance - System maintenance and cleanup tasks - data - Data processing and migration tasks - admin - Administrative and configuration tasks - report - Report generation and analytics tasks

Task Metadata

Enhance tasks with rich metadata: - Icons: Visual indicators using the application’s icon system - Danger flags: Warnings for potentially destructive operations - Expense flags: Indicators for resource-intensive tasks - Tags: Additional categorization and filtering options

Error Handling

Comprehensive error management: - Detailed error messages with context - Stack trace collection for debugging - Automatic retry mechanisms for transient failures - Graceful degradation for partial failures

Source Code

See Also