135 lines
4.4 KiB
Go
135 lines
4.4 KiB
Go
package model
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
const (
|
|
StatusPending = "pending"
|
|
StatusRunning = "running"
|
|
StatusDone = "done"
|
|
StatusFailed = "failed"
|
|
StatusCancelled = "cancelled"
|
|
)
|
|
|
|
type Job struct {
|
|
ID uuid.UUID `json:"id"`
|
|
OwnerService string `json:"owner_service"`
|
|
OwnerRef string `json:"owner_ref"`
|
|
TaskType string `json:"task_type"`
|
|
ModelProfile string `json:"model_profile"`
|
|
Priority int `json:"priority"`
|
|
Status string `json:"status"`
|
|
Attempts int `json:"attempts"`
|
|
MaxAttempts int `json:"max_attempts"`
|
|
Input json.RawMessage `json:"input"`
|
|
Result json.RawMessage `json:"result,omitempty"`
|
|
ErrorCode *string `json:"error_code,omitempty"`
|
|
ErrorMessage *string `json:"error_message,omitempty"`
|
|
ScheduledAt time.Time `json:"scheduled_at"`
|
|
StartedAt *time.Time `json:"started_at,omitempty"`
|
|
CompletedAt *time.Time `json:"completed_at,omitempty"`
|
|
WorkerID *string `json:"worker_id,omitempty"`
|
|
HeartbeatAt *time.Time `json:"heartbeat_at,omitempty"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
IdempotencyKey *string `json:"idempotency_key,omitempty"`
|
|
}
|
|
|
|
type JobSummary struct {
|
|
ID uuid.UUID `json:"id"`
|
|
OwnerService string `json:"owner_service"`
|
|
OwnerRef string `json:"owner_ref"`
|
|
TaskType string `json:"task_type"`
|
|
ModelProfile string `json:"model_profile"`
|
|
Priority int `json:"priority"`
|
|
Status string `json:"status"`
|
|
Attempts int `json:"attempts"`
|
|
MaxAttempts int `json:"max_attempts"`
|
|
ErrorCode *string `json:"error_code,omitempty"`
|
|
ErrorMessage *string `json:"error_message,omitempty"`
|
|
ScheduledAt time.Time `json:"scheduled_at"`
|
|
StartedAt *time.Time `json:"started_at,omitempty"`
|
|
CompletedAt *time.Time `json:"completed_at,omitempty"`
|
|
WorkerID *string `json:"worker_id,omitempty"`
|
|
HeartbeatAt *time.Time `json:"heartbeat_at,omitempty"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
type CreateJob struct {
|
|
OwnerService string `json:"owner_service"`
|
|
OwnerRef string `json:"owner_ref"`
|
|
TaskType string `json:"task_type"`
|
|
ModelProfile string `json:"model_profile"`
|
|
Priority int `json:"priority"`
|
|
MaxAttempts int `json:"max_attempts"`
|
|
Input json.RawMessage `json:"input"`
|
|
ScheduledAt *time.Time `json:"scheduled_at,omitempty"`
|
|
IdempotencyKey *string `json:"idempotency_key,omitempty"`
|
|
}
|
|
|
|
type ClaimJobs struct {
|
|
WorkerID string `json:"worker_id"`
|
|
TaskTypes []string `json:"task_types"`
|
|
ModelProfiles []string `json:"model_profiles"`
|
|
Limit int `json:"limit"`
|
|
}
|
|
|
|
type CompleteJob struct {
|
|
Result json.RawMessage `json:"result"`
|
|
}
|
|
|
|
type FailJob struct {
|
|
ErrorCode string `json:"error_code"`
|
|
ErrorMessage string `json:"error_message"`
|
|
}
|
|
|
|
type JobFilter struct {
|
|
OwnerService string `json:"owner_service,omitempty"`
|
|
OwnerRef string `json:"owner_ref,omitempty"`
|
|
TaskType string `json:"task_type,omitempty"`
|
|
ModelProfile string `json:"model_profile,omitempty"`
|
|
Statuses []string `json:"statuses,omitempty"`
|
|
ErrorCodes []string `json:"error_codes,omitempty"`
|
|
Limit int `json:"limit,omitempty"`
|
|
Offset int `json:"offset,omitempty"`
|
|
}
|
|
|
|
type BatchActionResult struct {
|
|
Updated int `json:"updated"`
|
|
}
|
|
|
|
type QueueStat struct {
|
|
TaskType string `json:"task_type"`
|
|
ModelProfile string `json:"model_profile"`
|
|
Status string `json:"status"`
|
|
Total int64 `json:"total"`
|
|
}
|
|
|
|
type ErrorStat struct {
|
|
TaskType string `json:"task_type"`
|
|
ModelProfile string `json:"model_profile"`
|
|
ErrorCode string `json:"error_code"`
|
|
Total int64 `json:"total"`
|
|
Last24h int64 `json:"last_24h"`
|
|
}
|
|
|
|
type OwnerStat struct {
|
|
OwnerService string `json:"owner_service"`
|
|
TaskType string `json:"task_type"`
|
|
ModelProfile string `json:"model_profile"`
|
|
Status string `json:"status"`
|
|
Total int64 `json:"total"`
|
|
}
|
|
|
|
type Stats struct {
|
|
At time.Time `json:"at"`
|
|
Queues []QueueStat `json:"queues"`
|
|
Owners []OwnerStat `json:"owners,omitempty"`
|
|
Errors []ErrorStat `json:"errors,omitempty"`
|
|
}
|