Replace the ad-hoc tables/procedures install layout with versioned, ordered SQL migrations tracked in broker_schema_migrations. Add optional least-privilege role provisioning (--with-roles), multi-tenant row-level security, lease-based job claiming with stale-lease recovery, and job dependencies -- both by job id and by fan-in job group. Add Docker/Compose support for running the broker and its test suite.
88 lines
2.9 KiB
Go
88 lines
2.9 KiB
Go
package models
|
|
|
|
import "time"
|
|
|
|
// Job represents a broker job
|
|
type Job struct {
|
|
ID int64 `json:"id"`
|
|
JobName string `json:"job_name"`
|
|
JobPriority int32 `json:"job_priority"`
|
|
JobQueue int `json:"job_queue"`
|
|
JobLanguage string `json:"job_language"`
|
|
ExecuteStr string `json:"execute_str"`
|
|
ExecuteResult string `json:"execute_result"`
|
|
ErrorMsg string `json:"error_msg"`
|
|
CompleteStatus int `json:"complete_status"`
|
|
RunAs string `json:"run_as"`
|
|
UserLogin string `json:"user_login"`
|
|
ScheduleID int64 `json:"schedule_id"`
|
|
TenantID string `json:"tenant_id"`
|
|
AttemptCount int `json:"attempt_count"`
|
|
MaxAttempts int `json:"max_attempts"`
|
|
LeaseToken string `json:"lease_token,omitempty"`
|
|
IdempotencyKey string `json:"idempotency_key,omitempty"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// WakeNotification is the payload sent over pg_notify('broker.event', ...).
|
|
// It carries only what a worker needs to decide whether to wake: the queue
|
|
// number. job_id is included solely for logging -- workers always re-claim
|
|
// via broker_get rather than executing the notified id directly.
|
|
type WakeNotification struct {
|
|
Queue int `json:"queue"`
|
|
JobID int64 `json:"job_id,omitempty"`
|
|
}
|
|
|
|
// Instance represents a broker instance
|
|
type Instance struct {
|
|
ID int64 `json:"id"`
|
|
Name string `json:"name"`
|
|
Hostname string `json:"hostname"`
|
|
PID int `json:"pid"`
|
|
Version string `json:"version"`
|
|
Status string `json:"status"` // active, inactive, shutdown
|
|
StartedAt time.Time `json:"started_at"`
|
|
LastPingAt time.Time `json:"last_ping_at"`
|
|
ShutdownAt time.Time `json:"shutdown_at"`
|
|
QueueCount int `json:"queue_count"`
|
|
JobsHandled int64 `json:"jobs_handled"`
|
|
}
|
|
|
|
// Schedule represents a job schedule
|
|
type Schedule struct {
|
|
ID int64 `json:"id"`
|
|
Name string `json:"name"`
|
|
CronExpr string `json:"cron_expr"`
|
|
Enabled bool `json:"enabled"`
|
|
JobName string `json:"job_name"`
|
|
JobPriority int32 `json:"job_priority"`
|
|
JobQueue int `json:"job_queue"`
|
|
ExecuteStr string `json:"execute_str"`
|
|
RunAs string `json:"run_as"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
LastRunAt time.Time `json:"last_run_at"`
|
|
NextRunAt time.Time `json:"next_run_at"`
|
|
}
|
|
|
|
// JobStatus represents job completion statuses
|
|
type JobStatus int
|
|
|
|
const (
|
|
JobStatusPending JobStatus = 0
|
|
JobStatusRunning JobStatus = 1
|
|
JobStatusCompleted JobStatus = 2
|
|
JobStatusFailed JobStatus = 3
|
|
JobStatusCancelled JobStatus = 4
|
|
)
|
|
|
|
// InstanceStatus represents instance statuses
|
|
type InstanceStatus string
|
|
|
|
const (
|
|
InstanceStatusActive InstanceStatus = "active"
|
|
InstanceStatusInactive InstanceStatus = "inactive"
|
|
InstanceStatusShutdown InstanceStatus = "shutdown"
|
|
)
|