grader

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2017 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddRunContext

func AddRunContext(
	ctx *Context,
	run *RunContext,
	input common.Input,
) error

AddRunContext registers a RunContext into the grader.

func NewGraderCachedInputFactory

func NewGraderCachedInputFactory(inputPath string) common.CachedInputFactory

func NewGraderInputFactory

func NewGraderInputFactory(
	problemName string,
	config *common.Config,
) common.InputFactory

Types

type Context

type Context struct {
	common.Context
	QueueManager    *QueueManager
	InflightMonitor *InflightMonitor
	InputManager    *common.InputManager
}

func NewContext

func NewContext(reader io.Reader) (*Context, error)

func (*Context) Close

func (context *Context) Close()

Close releases all resources owned by the context.

type GraderCachedInputFactory

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

GraderCachedInputFactory is a grader-specific CachedInputFactory.

func (*GraderCachedInputFactory) GetInputHash

func (factory *GraderCachedInputFactory) GetInputHash(
	dirname string,
	info os.FileInfo,
) (hash string, ok bool)

func (*GraderCachedInputFactory) NewInput

func (factory *GraderCachedInputFactory) NewInput(
	hash string,
	mgr *common.InputManager,
) common.Input

type GraderInput

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

GraderInput is an Input generated from a git repository that is then stored in a .tar.gz file that can be sent to a runner.

func (*GraderInput) Delete

func (input *GraderInput) Delete() error

func (*GraderInput) Persist

func (input *GraderInput) Persist() error

func (*GraderInput) Transmit

func (input *GraderInput) Transmit(w http.ResponseWriter) error

Transmit sends a serialized version of the Input to the runner. It sends a .tar.gz file with the Content-SHA1 header with the hexadecimal representation of its SHA-1 hash.

func (*GraderInput) Verify

func (input *GraderInput) Verify() error

type GraderInputFactory

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

GraderInputFactory is an InputFactory that can store specific versions of a problem's git repository into a .tar.gz file that can be easily shipped to runners.

func (*GraderInputFactory) NewInput

func (factory *GraderInputFactory) NewInput(
	hash string,
	mgr *common.InputManager,
) common.Input

type InflightMonitor

type InflightMonitor struct {
	sync.Mutex
	PostProcessor *RunPostProcessor
	// contains filtered or unexported fields
}

InflightMonitor manages all in-flight Runs (Runs that have been picked up by a runner) and tracks their state in case the runner becomes unresponsive.

func NewInflightMonitor

func NewInflightMonitor() *InflightMonitor

func (*InflightMonitor) Add

func (monitor *InflightMonitor) Add(
	run *RunContext,
	runner string,
) *InflightRun

Add creates an InflightRun wrapper for the specified RunContext, adds it to the InflightMonitor, and monitors it for timeouts. A RunContext can be later accesssed through its attempt ID.

func (*InflightMonitor) Get

func (monitor *InflightMonitor) Get(attemptID uint64) (*RunContext, <-chan struct{}, bool)

Get returns the RunContext associated with the specified attempt ID.

func (*InflightMonitor) GetRunData

func (monitor *InflightMonitor) GetRunData() []*RunData

func (*InflightMonitor) MarshalJSON

func (monitor *InflightMonitor) MarshalJSON() ([]byte, error)

func (*InflightMonitor) Remove

func (monitor *InflightMonitor) Remove(attemptID uint64)

Remove removes the specified attempt ID from the in-flight runs and signals the RunContext for completion.

type InflightRun

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

InflightRun is a wrapper around a RunContext when it is handed off a queue and a runner has been assigned to it.

type Queue

type Queue struct {
	Name string
	// contains filtered or unexported fields
}

Queue represents a RunContext queue with three discrete priorities.

func (*Queue) AddRun

func (queue *Queue) AddRun(run *RunContext)

func (*Queue) GetRun

func (queue *Queue) GetRun(
	runner string,
	monitor *InflightMonitor,
	closeNotifier <-chan bool,
) (*RunContext, <-chan struct{}, bool)

GetRun dequeues a RunContext from the queue and adds it to the global InflightMonitor. This function will block if there are no RunContext objects in the queue.

type QueueInfo

type QueueInfo struct {
	Lengths [3]int
}

QueueInfo has information about one queue.

type QueueManager

type QueueManager struct {
	sync.Mutex
	// contains filtered or unexported fields
}

QueueManager is an expvar-friendly manager for Queues.

func NewQueueManager

func NewQueueManager(channelLength int) *QueueManager

func (*QueueManager) Add

func (manager *QueueManager) Add(name string) *Queue

func (*QueueManager) Get

func (manager *QueueManager) Get(name string) (*Queue, error)

func (*QueueManager) GetQueueInfo

func (manager *QueueManager) GetQueueInfo() map[string]QueueInfo

func (*QueueManager) MarshalJSON

func (manager *QueueManager) MarshalJSON() ([]byte, error)

type RunContext

type RunContext struct {
	RunInfo

	// These fields are there so that the RunContext can be used as a normal
	// Context.
	Log            log15.Logger
	EventCollector common.EventCollector
	EventFactory   *common.EventFactory
	Config         *common.Config
	// contains filtered or unexported fields
}

RunContext is a wrapper around a RunInfo. This is used when a Run is sitting on a Queue on the grader.

func NewEmptyRunContext

func NewEmptyRunContext(ctx *Context) *RunContext

func (*RunContext) AppendRunnerLogs

func (run *RunContext) AppendRunnerLogs(runnerName string, contents []byte)

func (*RunContext) Close

func (run *RunContext) Close()

func (*RunContext) Debug

func (run *RunContext) Debug() error

func (*RunContext) Ready

func (run *RunContext) Ready() <-chan struct{}

func (*RunContext) Requeue

func (run *RunContext) Requeue(lastAttempt bool) bool

Requeue adds a RunContext back to the Queue from where it came from, if it has any retries left. It always adds the RunContext to the highest-priority queue.

func (*RunContext) String

func (run *RunContext) String() string

type RunData

type RunData struct {
	AttemptID    uint64
	ID           int64
	GUID         string
	Queue        string
	AttemptsLeft int
	Runner       string
	Time         int64
	Elapsed      int64
}

RunData represents the data of a single run.

type RunInfo

type RunInfo struct {
	ID          int64
	GUID        string
	Contest     *string
	ProblemName string
	Run         *common.Run
	Result      runner.RunResult
	GradeDir    string

	CreationTime time.Time
}

RunInfo holds the necessary data of a Run, even after the RunContext is gone.

type RunPostProcessor

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

func NewRunPostProcessor

func NewRunPostProcessor() *RunPostProcessor

func (*RunPostProcessor) AddListener

func (postProcessor *RunPostProcessor) AddListener(c chan<- *RunInfo)

func (*RunPostProcessor) Close

func (postProcessor *RunPostProcessor) Close()

func (*RunPostProcessor) PostProcess

func (postProcessor *RunPostProcessor) PostProcess(run *RunInfo)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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