94 lines
3.2 KiB
Go
94 lines
3.2 KiB
Go
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"`
|
|
}
|