Add job-related models to bindata and update system models

- Added new models for job management: category, execution, job, and log.
- Updated bindata.go to include paths for the new job models.
- Modified model.go and utils.go to register the new job models in system and test mappings, ensuring they are accessible in the application.
This commit is contained in:
Max 2025-08-30 17:43:08 +08:00
parent ae965d0b32
commit 1664355401
7 changed files with 1000 additions and 134 deletions

File diff suppressed because one or more lines are too long

View file

@ -27,6 +27,10 @@ var systemModels = map[string]string{
"__yao.config": "yao/models/config.mod.yao",
"__yao.dsl": "yao/models/dsl.mod.yao",
"__yao.history": "yao/models/history.mod.yao",
"__yao.job.category": "yao/models/job/category.mod.yao",
"__yao.job": "yao/models/job/job.mod.yao",
"__yao.job.execution": "yao/models/job/execution.mod.yao",
"__yao.job.log": "yao/models/job/log.mod.yao",
"__yao.kb.collection": "yao/models/kb/collection.mod.yao",
"__yao.kb.document": "yao/models/kb/document.mod.yao",
"__yao.user": "yao/models/user.mod.yao",

View file

@ -43,6 +43,10 @@ var testSystemModels = map[string]string{
"__yao.config": "yao/models/config.mod.yao",
"__yao.dsl": "yao/models/dsl.mod.yao",
"__yao.history": "yao/models/history.mod.yao",
"__yao.job.category": "yao/models/job/category.mod.yao",
"__yao.job": "yao/models/job/job.mod.yao",
"__yao.job.execution": "yao/models/job/execution.mod.yao",
"__yao.job.log": "yao/models/job/log.mod.yao",
"__yao.kb.collection": "yao/models/kb/collection.mod.yao",
"__yao.kb.document": "yao/models/kb/document.mod.yao",
"__yao.user": "yao/models/user.mod.yao",

View file

@ -0,0 +1,91 @@
{
"name": "category",
"label": "Job Category",
"description": "Job category table for organizing different types of jobs",
"tags": ["system"],
"builtin": true,
"readonly": false,
"sort": 9999,
"table": {
"name": "job_category",
"comment": "Job Category table"
},
"columns": [
{
"name": "id",
"type": "ID",
"label": "ID",
"comment": "Auto-increment primary key"
},
{
"name": "category_id",
"type": "string",
"label": "Category ID",
"comment": "Unique string identifier for the category",
"length": 64,
"nullable": false,
"unique": true
},
{
"name": "name",
"type": "string",
"label": "Category Name",
"comment": "Display name of the category",
"length": 255,
"nullable": false,
"index": true
},
{
"name": "icon",
"type": "string",
"label": "Icon",
"comment": "Icon identifier for the category",
"length": 100,
"nullable": true
},
{
"name": "description",
"type": "text",
"label": "Description",
"comment": "Category description",
"nullable": true
},
{
"name": "sort",
"type": "integer",
"label": "Sort Order",
"comment": "Sort order for display",
"default": 0,
"nullable": false
},
{
"name": "system",
"type": "boolean",
"label": "System Category",
"comment": "Whether this is a system category",
"default": false,
"nullable": false
},
{
"name": "enabled",
"type": "boolean",
"label": "Enabled",
"comment": "Whether this category is enabled",
"default": true,
"nullable": false,
"index": true
},
{
"name": "readonly",
"type": "boolean",
"label": "Readonly",
"comment": "Whether this category is read-only",
"default": false,
"nullable": false
}
],
"option": {
"permission": true,
"timestamps": true
}
}

View file

@ -0,0 +1,249 @@
{
"name": "execution",
"label": "Job Execution",
"description": "Job execution table for tracking individual execution instances",
"tags": ["system"],
"builtin": true,
"readonly": false,
"sort": 9999,
"table": {
"name": "job_execution",
"comment": "Job Execution table"
},
"columns": [
{
"name": "id",
"type": "ID",
"label": "ID",
"comment": "Auto-increment primary key"
},
{
"name": "execution_id",
"type": "string",
"label": "Execution ID",
"comment": "Unique string identifier for the execution instance",
"length": 64,
"nullable": false,
"unique": true
},
{
"name": "job_id",
"type": "string",
"label": "Job ID",
"comment": "Reference to the job this execution belongs to",
"length": 64,
"nullable": false,
"index": true
},
{
"name": "status",
"type": "enum",
"label": "Status",
"comment": "Execution instance status",
"option": [
"queued", // Execution is queued and waiting to start
"initializing", // Execution is being initialized
"running", // Execution is currently in progress
"completed", // Execution finished successfully
"failed", // Execution failed with errors
"cancelled", // Execution was cancelled by user/system
"timeout", // Execution timed out
"killed" // Execution was forcefully terminated
],
"default": "queued",
"nullable": false,
"index": true
},
{
"name": "trigger_category",
"type": "enum",
"label": "Trigger Category",
"comment": "High-level trigger category",
"option": [
"manual", // User manually triggered
"scheduled", // Time-based scheduling (cron, interval)
"event", // Event-driven triggers
"api", // External API calls
"system", // System-initiated triggers
"dependency" // Dependency-based triggers
],
"nullable": false,
"index": true
},
{
"name": "trigger_source",
"type": "string",
"label": "Trigger Source",
"comment": "Specific trigger source identifier (extensible)",
"length": 128,
"nullable": true,
"index": true
},
{
"name": "trigger_context",
"type": "json",
"label": "Trigger Context",
"comment": "Additional trigger context and metadata",
"nullable": true
},
{
"name": "scheduled_at",
"type": "timestamp",
"label": "Scheduled At",
"comment": "When this execution was scheduled to run (for scheduled jobs)",
"nullable": true,
"index": true
},
{
"name": "worker_id",
"type": "string",
"label": "Worker ID",
"comment": "Worker instance handling this execution",
"length": 128,
"nullable": true,
"index": true
},
{
"name": "process_id",
"type": "string",
"label": "Process ID",
"comment": "Process ID for heavyweight executions",
"length": 64,
"nullable": true,
"index": true
},
{
"name": "retry_attempt",
"type": "integer",
"label": "Retry Attempt",
"comment": "Which retry attempt this is (0 for first attempt)",
"default": 0,
"nullable": false
},
{
"name": "parent_execution_id",
"type": "string",
"label": "Parent Execution ID",
"comment": "Reference to parent execution if this is a retry",
"length": 64,
"nullable": true,
"index": true
},
{
"name": "started_at",
"type": "timestamp",
"label": "Started At",
"comment": "Timestamp when execution started",
"nullable": true,
"index": true
},
{
"name": "ended_at",
"type": "timestamp",
"label": "Ended At",
"comment": "Timestamp when execution ended",
"nullable": true,
"index": true
},
{
"name": "timeout_seconds",
"type": "integer",
"label": "Timeout Seconds",
"comment": "Actual timeout used for this execution (inherited from job or overridden)",
"nullable": true
},
{
"name": "duration",
"type": "integer",
"label": "Duration",
"comment": "Execution duration in milliseconds",
"nullable": true
},
{
"name": "progress",
"type": "integer",
"label": "Progress",
"comment": "Execution progress percentage (0-100)",
"default": 0,
"nullable": false
},
{
"name": "config_snapshot",
"type": "json",
"label": "Config Snapshot",
"comment": "Snapshot of job configuration at execution time",
"nullable": true
},
{
"name": "result",
"type": "json",
"label": "Result",
"comment": "Execution result data",
"nullable": true
},
{
"name": "error_info",
"type": "json",
"label": "Error Info",
"comment": "Structured error information if execution failed",
"nullable": true
},
{
"name": "stack_trace",
"type": "text",
"label": "Stack Trace",
"comment": "Stack trace information when execution fails",
"nullable": true
},
{
"name": "metrics",
"type": "json",
"label": "Metrics",
"comment": "Execution metrics like memory usage, CPU time, etc.",
"nullable": true
},
{
"name": "context",
"type": "json",
"label": "Context",
"comment": "Additional execution context and metadata",
"nullable": true
}
],
"indexes": [
{
"name": "idx_execution_job_started",
"columns": ["job_id", "started_at"],
"comment": "Composite index for job execution history queries"
},
{
"name": "idx_execution_status_started",
"columns": ["status", "started_at"],
"comment": "Composite index for status-based queries with time ordering"
},
{
"name": "idx_execution_worker_started",
"columns": ["worker_id", "started_at"],
"comment": "Composite index for worker execution history"
},
{
"name": "idx_execution_trigger_started",
"columns": ["trigger_category", "started_at"],
"comment": "Composite index for trigger category analysis"
},
{
"name": "idx_execution_trigger_source",
"columns": ["trigger_source", "started_at"],
"comment": "Composite index for trigger source analysis"
},
{
"name": "idx_execution_parent_retry",
"columns": ["parent_execution_id", "retry_attempt"],
"comment": "Composite index for retry chain tracking"
}
],
"option": {
"permission": true,
"timestamps": true
}
}

240
yao/models/job/job.mod.yao Normal file
View file

@ -0,0 +1,240 @@
{
"name": "job",
"label": "Job",
"description": "Job table for managing task execution and scheduling",
"tags": ["system"],
"builtin": true,
"readonly": false,
"sort": 9999,
"table": {
"name": "job",
"comment": "Job main table"
},
"columns": [
{
"name": "id",
"type": "ID",
"label": "ID",
"comment": "Auto-increment primary key"
},
{
"name": "job_id",
"type": "string",
"label": "Job ID",
"comment": "Unique string identifier for the job",
"length": 64,
"nullable": false,
"unique": true
},
{
"name": "name",
"type": "string",
"label": "Job Name",
"comment": "Display name of the job",
"length": 255,
"nullable": false,
"index": true
},
{
"name": "icon",
"type": "string",
"label": "Icon",
"comment": "Icon identifier for the job",
"length": 100,
"nullable": true
},
{
"name": "description",
"type": "text",
"label": "Description",
"comment": "Job description",
"nullable": true
},
{
"name": "category_id",
"type": "string",
"label": "Category ID",
"comment": "Reference to the category this job belongs to",
"length": 64,
"nullable": false,
"index": true
},
{
"name": "status",
"type": "enum",
"label": "Status",
"comment": "Job overall status",
"option": [
"draft", // Job is being configured, not ready to run
"ready", // Job is ready to be executed
"running", // Job has active execution(s)
"paused", // Job execution is temporarily paused
"completed", // Job finished successfully (for 'once' jobs)
"failed", // Job failed and won't retry anymore
"disabled" // Job is disabled by user/system
],
"default": "draft",
"nullable": false,
"index": true
},
{
"name": "process_type",
"type": "enum",
"label": "Process Type",
"comment": "Job execution process type",
"option": [
"goroutine", // Execute using Go goroutine (lightweight, fast)
"process" // Execute as independent process (isolated, heavyweight)
],
"default": "goroutine",
"nullable": false,
"index": true
},
{
"name": "schedule_type",
"type": "enum",
"label": "Schedule Type",
"comment": "Job scheduling pattern",
"option": [
"once", // Execute once and finish
"cron", // Execute based on cron schedule
"daemon" // Run continuously as daemon process
],
"default": "once",
"nullable": false,
"index": true
},
{
"name": "schedule_expression",
"type": "string",
"label": "Schedule Expression",
"comment": "Cron expression for scheduled jobs",
"length": 100,
"nullable": true
},
{
"name": "max_retry_count",
"type": "integer",
"label": "Max Retry Count",
"comment": "Maximum number of retry attempts on failure",
"default": 0,
"nullable": false
},
{
"name": "default_timeout",
"type": "integer",
"label": "Default Timeout",
"comment": "Default execution timeout in seconds (can be overridden per execution)",
"nullable": true
},
{
"name": "priority",
"type": "integer",
"label": "Priority",
"comment": "Job execution priority (higher number = higher priority)",
"default": 0,
"nullable": false,
"index": true
},
{
"name": "created_by",
"type": "string",
"label": "Created By",
"comment": "User who created this job",
"length": 128,
"nullable": false,
"index": true
},
{
"name": "next_run_at",
"type": "timestamp",
"label": "Next Run At",
"comment": "Timestamp for next scheduled execution",
"nullable": true,
"index": true
},
{
"name": "last_run_at",
"type": "timestamp",
"label": "Last Run At",
"comment": "Timestamp of last execution",
"nullable": true,
"index": true
},
{
"name": "current_execution_id",
"type": "string",
"label": "Current Execution ID",
"comment": "Reference to current/latest execution instance",
"length": 64,
"nullable": true,
"index": true
},
{
"name": "config",
"type": "json",
"label": "Configuration",
"comment": "Job configuration parameters",
"nullable": true
},
{
"name": "sort",
"type": "integer",
"label": "Sort Order",
"comment": "Sort order for display",
"default": 0,
"nullable": false
},
{
"name": "enabled",
"type": "boolean",
"label": "Enabled",
"comment": "Whether this job is enabled for execution",
"default": true,
"nullable": false,
"index": true
},
{
"name": "system",
"type": "boolean",
"label": "System Job",
"comment": "Whether this is a system job",
"default": false,
"nullable": false
},
{
"name": "readonly",
"type": "boolean",
"label": "Readonly",
"comment": "Whether this job is read-only",
"default": false,
"nullable": false
}
],
"indexes": [
{
"name": "idx_job_category_status",
"columns": ["category_id", "status"],
"comment": "Composite index for category and status queries"
},
{
"name": "idx_job_process_type_status",
"columns": ["process_type", "status"],
"comment": "Composite index for process type and status queries"
},
{
"name": "idx_job_schedule_type_next_run",
"columns": ["schedule_type", "next_run_at"],
"comment": "Composite index for scheduled job queries"
},
{
"name": "idx_job_created_by_status",
"columns": ["created_by", "status"],
"comment": "Composite index for user job queries"
}
],
"option": {
"permission": true,
"timestamps": true
}
}

184
yao/models/job/log.mod.yao Normal file
View file

@ -0,0 +1,184 @@
{
"name": "log",
"label": "Job Log",
"description": "Job log table for tracking job execution logs and events",
"tags": ["system"],
"builtin": true,
"readonly": false,
"sort": 9999,
"table": {
"name": "job_log",
"comment": "Job Log table"
},
"columns": [
{
"name": "id",
"type": "ID",
"label": "ID",
"comment": "Auto-increment primary key"
},
{
"name": "job_id",
"type": "string",
"label": "Job ID",
"comment": "Reference to the job this log belongs to",
"length": 64,
"nullable": false,
"index": true
},
{
"name": "level",
"type": "enum",
"label": "Log Level",
"comment": "Log level indicating severity",
"option": [
"debug", // Debug information for development
"info", // General information about execution
"warning", // Warning messages for potential issues
"error", // Error messages for failures
"fatal", // Fatal errors that stop execution
"retry" // Retry attempt information
],
"default": "info",
"nullable": false,
"index": true
},
{
"name": "message",
"type": "text",
"label": "Message",
"comment": "Log message content",
"nullable": false
},
{
"name": "context",
"type": "json",
"label": "Context",
"comment": "Additional context data for the log entry",
"nullable": true
},
{
"name": "source",
"type": "string",
"label": "Source",
"comment": "Source component or module that generated the log",
"length": 128,
"nullable": true,
"index": true
},
{
"name": "execution_id",
"type": "string",
"label": "Execution ID",
"comment": "Unique identifier for this execution run (useful for retry scenarios)",
"length": 64,
"nullable": true,
"index": true
},
{
"name": "step",
"type": "string",
"label": "Step",
"comment": "Execution step or phase when this log was generated",
"length": 100,
"nullable": true,
"index": true
},
{
"name": "progress",
"type": "integer",
"label": "Progress",
"comment": "Progress percentage at the time of this log (0-100)",
"nullable": true
},
{
"name": "duration",
"type": "integer",
"label": "Duration",
"comment": "Duration in milliseconds for the operation (if applicable)",
"nullable": true
},
{
"name": "error_code",
"type": "string",
"label": "Error Code",
"comment": "Error code for error-level logs",
"length": 50,
"nullable": true,
"index": true
},
{
"name": "stack_trace",
"type": "text",
"label": "Stack Trace",
"comment": "Stack trace for error logs",
"nullable": true
},
{
"name": "worker_id",
"type": "string",
"label": "Worker ID",
"comment": "Worker instance that generated this log",
"length": 128,
"nullable": true,
"index": true
},
{
"name": "process_id",
"type": "string",
"label": "Process ID",
"comment": "Process ID for heavyweight jobs",
"length": 64,
"nullable": true,
"index": true
},
{
"name": "timestamp",
"type": "timestamp",
"label": "Timestamp",
"comment": "Timestamp when the log was generated",
"nullable": false,
"index": true,
"default": "now()"
},
{
"name": "sequence",
"type": "integer",
"label": "Sequence",
"comment": "Sequence number within the job execution for ordering",
"nullable": false,
"default": 0
}
],
"indexes": [
{
"name": "idx_log_job_timestamp",
"columns": ["job_id", "timestamp"],
"comment": "Composite index for job log queries ordered by time"
},
{
"name": "idx_log_job_level",
"columns": ["job_id", "level"],
"comment": "Composite index for filtering logs by job and level"
},
{
"name": "idx_log_execution_sequence",
"columns": ["execution_id", "sequence"],
"comment": "Composite index for ordering logs within an execution"
},
{
"name": "idx_log_level_timestamp",
"columns": ["level", "timestamp"],
"comment": "Composite index for filtering logs by level and time"
},
{
"name": "idx_log_worker_timestamp",
"columns": ["worker_id", "timestamp"],
"comment": "Composite index for worker-specific log queries"
}
],
"option": {
"permission": true,
"timestamps": true
}
}