Files
ai-service/internal/model/job.go
2026-06-08 13:23:10 +03:00

72 lines
2.3 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"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
IdempotencyKey *string `json:"idempotency_key,omitempty"`
}
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 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 Stats struct {
At time.Time `json:"at"`
Queues []QueueStat `json:"queues"`
Errors []ErrorStat `json:"errors,omitempty"`
}