feat(model): add Task model, DTOs, and status constants for task submission system
This commit is contained in:
93
internal/model/task.go
Normal file
93
internal/model/task.go
Normal file
@@ -0,0 +1,93 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Task status constants.
|
||||
const (
|
||||
TaskStatusSubmitted = "submitted"
|
||||
TaskStatusPreparing = "preparing"
|
||||
TaskStatusDownloading = "downloading"
|
||||
TaskStatusReady = "ready"
|
||||
TaskStatusQueued = "queued"
|
||||
TaskStatusRunning = "running"
|
||||
TaskStatusCompleted = "completed"
|
||||
TaskStatusFailed = "failed"
|
||||
)
|
||||
|
||||
// Task step constants for step-level retry tracking.
|
||||
const (
|
||||
TaskStepPreparing = "preparing"
|
||||
TaskStepDownloading = "downloading"
|
||||
TaskStepSubmitting = "submitting"
|
||||
)
|
||||
|
||||
// Task represents an HPC task submitted through the application framework.
|
||||
type Task struct {
|
||||
ID int64 `gorm:"primaryKey;autoIncrement" json:"id"`
|
||||
TaskName string `gorm:"size:255" json:"task_name"`
|
||||
AppID int64 `json:"app_id"`
|
||||
AppName string `gorm:"size:255" json:"app_name"`
|
||||
Status string `json:"status"`
|
||||
CurrentStep string `json:"current_step"`
|
||||
RetryCount int `json:"retry_count"`
|
||||
Values json.RawMessage `gorm:"type:text" json:"values,omitempty"`
|
||||
InputFileIDs json.RawMessage `json:"input_file_ids" gorm:"column:input_file_ids;type:text"`
|
||||
Script string `json:"script,omitempty"`
|
||||
SlurmJobID *int32 `json:"slurm_job_id,omitempty"`
|
||||
WorkDir string `json:"work_dir,omitempty"`
|
||||
Partition string `json:"partition,omitempty"`
|
||||
ErrorMessage string `json:"error_message,omitempty"`
|
||||
UserID string `json:"user_id"`
|
||||
SubmittedAt time.Time `json:"submitted_at"`
|
||||
StartedAt *time.Time `json:"started_at,omitempty"`
|
||||
FinishedAt *time.Time `json:"finished_at,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"`
|
||||
}
|
||||
|
||||
func (Task) TableName() string {
|
||||
return "hpc_tasks"
|
||||
}
|
||||
|
||||
// CreateTaskRequest is the DTO for creating a new task.
|
||||
type CreateTaskRequest struct {
|
||||
AppID int64 `json:"app_id" binding:"required"`
|
||||
TaskName string `json:"task_name"`
|
||||
Values map[string]string `json:"values"`
|
||||
InputFileIDs []int64 `json:"file_ids"`
|
||||
}
|
||||
|
||||
// TaskResponse is the DTO returned in API responses.
|
||||
type TaskResponse struct {
|
||||
ID int64 `json:"id"`
|
||||
TaskName string `json:"task_name"`
|
||||
AppID int64 `json:"app_id"`
|
||||
AppName string `json:"app_name"`
|
||||
Status string `json:"status"`
|
||||
CurrentStep string `json:"current_step"`
|
||||
RetryCount int `json:"retry_count"`
|
||||
SlurmJobID *int32 `json:"slurm_job_id"`
|
||||
WorkDir string `json:"work_dir"`
|
||||
ErrorMessage string `json:"error_message"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// TaskListResponse is the paginated response for listing tasks.
|
||||
type TaskListResponse struct {
|
||||
Items []TaskResponse `json:"items"`
|
||||
Total int64 `json:"total"`
|
||||
}
|
||||
|
||||
// TaskListQuery contains query parameters for listing tasks.
|
||||
type TaskListQuery struct {
|
||||
Page int `form:"page" json:"page,omitempty"`
|
||||
PageSize int `form:"page_size" json:"page_size,omitempty"`
|
||||
Status string `form:"status" json:"status,omitempty"`
|
||||
}
|
||||
Reference in New Issue
Block a user