From a94abdb47986aa0fdefde461f84ccb3ee04b67e7 Mon Sep 17 00:00:00 2001 From: douxu Date: Thu, 5 Mar 2026 17:15:51 +0800 Subject: [PATCH] initialize the asynchronous task system's initial structure --- task/types.go | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 task/types.go diff --git a/task/types.go b/task/types.go new file mode 100644 index 0000000..8ea5c73 --- /dev/null +++ b/task/types.go @@ -0,0 +1,55 @@ +package task + +import ( + "time" +) + +type TaskStatus string + +const ( + StatusPending TaskStatus = "PENDING" + StatusRunning TaskStatus = "RUNNING" + StatusCompleted TaskStatus = "COMPLETED" + StatusFailed TaskStatus = "FAILED" +) + +// TaskType 定义异步任务的具体业务类型 +type TaskType string + +const ( + TypeTopologyAnalysis TaskType = "TOPOLOGY_ANALYSIS" + TypeEventAnalysis TaskType = "EVENT_ANALYSIS" + TypeBatchImport TaskType = "BATCH_IMPORT" +) + +type Task struct { + ID string `bson:"_id" json:"id"` + Type TaskType `bson:"type" json:"type"` + Status TaskStatus `bson:"status" json:"status"` + Priority int `bson:"priority" json:"priority"` + + Params map[string]interface{} `bson:"params" json:"params"` + Result map[string]interface{} `bson:"result,omitempty" json:"result"` + ErrorMsg string `bson:"error_msg,omitempty" json:"error_msg"` + + CreatedAt time.Time `bson:"created_at" json:"created_at"` + StartedAt time.Time `bson:"started_at,omitempty" json:"started_at"` + CompletedAt time.Time `bson:"completed_at,omitempty" json:"completed_at"` +} + +type TopologyParams struct { + CheckIsland bool `json:"check_island"` + CheckShort bool `json:"check_short"` + BaseModelIDs []string `json:"base_model_ids"` +} + +type EventAnalysisParams struct { + MotorID string `json:"motor_id"` + TriggerID string `json:"trigger_id"` + DurationMS int `json:"duration_ms"` +} + +type BatchImportParams struct { + FileName string `json:"file_name"` + FilePath string `json:"file_path"` +}