judger

package
v0.4.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2025 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadAllContestsAndProblems

func LoadAllContestsAndProblems(contestDirs []string) (map[string]*Contest, map[string]*Problem, error)

func RecoverAndCleanup

func RecoverAndCleanup(db *gorm.DB, cfg *config.Config) error

RecoverAndCleanup handles the recovery process on application startup. It finds submissions and containers that were in a 'Running' state and cleans up their associated Docker containers before marking them as 'Failed' in the database.

func RequeuePendingSubmissions

func RequeuePendingSubmissions(db *gorm.DB, s *Scheduler, appState *AppState) error

RequeuePendingSubmissions loads submissions with 'Queued' status from the DB and adds them back to the scheduler's queue on startup.

Types

type AppState

type AppState struct {
	sync.RWMutex
	Contests            map[string]*Contest
	Problems            map[string]*Problem
	ProblemToContestMap map[string]*Contest
}

AppState holds the shared, reloadable state of contests and problems.

type ClusterState

type ClusterState struct {
	sync.Mutex
	*config.Cluster
	Nodes map[string]*NodeState `json:"nodes"`
}

type Contest

type Contest struct {
	ID          string    `yaml:"id" json:"id"`
	Name        string    `yaml:"name" json:"name"`
	StartTime   time.Time `yaml:"starttime" json:"starttime"`
	EndTime     time.Time `yaml:"endtime" json:"endtime"`
	ProblemDirs []string  `yaml:"problems" json:"problem_dirs"`
	ProblemIDs  []string  `yaml:"problem_ids" json:"problem_ids"`
	Description string    `json:"description"`
	BasePath    string    `json:"-"` // Store the base path to find assets
}

type Dispatcher

type Dispatcher struct {
	// contains filtered or unexported fields
}

func NewDispatcher

func NewDispatcher(cfg *config.Config, db *gorm.DB, scheduler *Scheduler, appState *AppState) *Dispatcher

func (*Dispatcher) Dispatch

func (d *Dispatcher) Dispatch(sub *models.Submission, prob *Problem, node *NodeState, allocatedCores []int)

type DockerManager

type DockerManager struct {
	// contains filtered or unexported fields
}

func NewDockerManager

func NewDockerManager(cfg config.DockerConfig) (*DockerManager, error)

func (*DockerManager) CleanupContainer

func (m *DockerManager) CleanupContainer(containerID string)

func (*DockerManager) CopyToContainer

func (m *DockerManager) CopyToContainer(containerID string, srcDir string, dstDir string) error

func (*DockerManager) CreateContainer

func (m *DockerManager) CreateContainer(image, workDir string, cpu int, cpusetCpus string, memory int64, asRoot bool, mounts []Mount, networkEnabled bool, envs []string) (string, error)

func (*DockerManager) ExecInContainer

func (m *DockerManager) ExecInContainer(ctx context.Context, containerID string, cmd []string, outputCallback func(streamType string, data []byte)) (ExecResult, error)

func (*DockerManager) StartContainer

func (m *DockerManager) StartContainer(containerID string) error

type ExecResult

type ExecResult struct {
	Stdout   string
	Stderr   string
	ExitCode int
}

type JudgeResult

type JudgeResult struct {
	Score       int                    `json:"score"`
	Performance float64                `json:"performance"`
	Info        map[string]interface{} `json:"info"`
}

type Mount

type Mount struct {
	Type     string `yaml:"type" json:"type"`
	Source   string `yaml:"source" json:"source"`
	Target   string `yaml:"target" json:"target"`
	ReadOnly *bool  `yaml:"readonly" json:"readonly"`
}

type NodeDetail

type NodeDetail struct {
	*config.Node
	UsedMemory int64  `json:"used_memory"`
	UsedCores  []bool `json:"used_cores"`
	IsPaused   bool   `json:"is_paused"`
}

type NodeState

type NodeState struct {
	sync.Mutex
	*config.Node
	UsedMemory int64  `json:"used_memory"`
	UsedCores  []bool `json:"used_cores"`
	IsPaused   bool   `json:"is_paused"`
}

type Problem

type Problem struct {
	ID             string         `yaml:"id" json:"id"`
	Name           string         `yaml:"name" json:"name"`
	StartTime      time.Time      `yaml:"starttime" json:"starttime"`
	EndTime        time.Time      `yaml:"endtime" json:"endtime"`
	MaxSubmissions int            `yaml:"max_submissions" json:"max_submissions"`
	Cluster        string         `yaml:"cluster" json:"cluster"`
	CPU            int            `yaml:"cpu" json:"cpu"`
	Memory         int64          `yaml:"memory" json:"memory"`
	Upload         UploadLimit    `yaml:"upload" json:"upload"`
	Workflow       []WorkflowStep `yaml:"workflow" json:"workflow"`
	Score          ScoreConfig    `yaml:"score" json:"score"`
	Description    string         `json:"description"`
	BasePath       string         `json:"-"` // Store the base path to find assets
}

type QueuedSubmission

type QueuedSubmission struct {
	Submission *models.Submission
	Problem    *Problem
}

type Scheduler

type Scheduler struct {
	// contains filtered or unexported fields
}

func NewScheduler

func NewScheduler(cfg *config.Config, db *gorm.DB, appState *AppState) *Scheduler

func (*Scheduler) GetClusterStates

func (s *Scheduler) GetClusterStates() map[string]ClusterState

func (*Scheduler) GetNodeDetails

func (s *Scheduler) GetNodeDetails(clusterName, nodeName string) (*NodeDetail, error)

func (*Scheduler) GetQueueLengths

func (s *Scheduler) GetQueueLengths() map[string]int

func (*Scheduler) PauseNode

func (s *Scheduler) PauseNode(clusterName, nodeName string) error

func (*Scheduler) ReleaseResources

func (s *Scheduler) ReleaseResources(clusterName, nodeName string, coresToRelease []int, memory int64)

func (*Scheduler) ResumeNode

func (s *Scheduler) ResumeNode(clusterName, nodeName string) error

func (*Scheduler) Run

func (s *Scheduler) Run()

func (*Scheduler) Submit

func (s *Scheduler) Submit(submission *models.Submission, problem *Problem)

type ScoreConfig

type ScoreConfig struct {
	Mode                string `yaml:"mode" json:"mode"`
	MaxPerformanceScore int    `yaml:"max_performance_score" json:"max_performance_score"`
}

type UploadLimit

type UploadLimit struct {
	MaxNum      int      `yaml:"maxnum" json:"max_num"`
	MaxSize     int      `yaml:"maxsize" json:"max_size"`
	UploadForm  bool     `yaml:"upload_form" json:"upload_form"`
	Editor      bool     `yaml:"editor" json:"editor"`
	EditorFiles []string `yaml:"editor_files" json:"editor_files"`
}

type WorkflowStep

type WorkflowStep struct {
	Name    string     `yaml:"name" json:"name"`
	Image   string     `yaml:"image" json:"image"`
	Root    bool       `yaml:"root" json:"root"`
	Timeout int        `yaml:"timeout" json:"timeout"`
	Show    bool       `yaml:"show" json:"show"`
	Steps   [][]string `yaml:"steps" json:"steps"`
	Mounts  []Mount    `yaml:"mounts" json:"mounts"`
	Network bool       `yaml:"network" json:"network"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL