pool

package
v0.0.0-...-6ed6190 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionOutput

type ActionOutput struct {
	// ExecutionInformation is a channel that is used to send the execution information
	// to the client which contains the name of the temporary directory and the user.
	ExecutionInformation chan ExecutionInformation
	// Once is a channel that is used to send the code output to the client once with the
	// REST API.
	Once chan CodeOutput
	// Stream is a channel that is used to send the code output to the client continuously
	// with the WebSocket API.
	Stream chan StreamOutput
}

type CodeOutput

type CodeOutput struct {
	User          User
	TempDirName   string
	CompileOutput Output
	RunOutput     Output
	TestOutput    TestOutput
}

type ConcurrentQueue

type ConcurrentQueue[T any] struct {
	// contains filtered or unexported fields
}

ConcurrentQueue is a concurrent implementation of the designed `Queue`.

func NewConcurrentQueue

func NewConcurrentQueue[T any]() *ConcurrentQueue[T]

NewConcurrentQueue creates a new queue with any value type and areturns it.

type ExecutionInformation

type ExecutionInformation struct {
	TempDirName string
	User        *User
}

type Output

type Output struct {
	Result string `json:"result"`
	Error  string `json:"error"`
	Time   int64  `json:"time"`
}

type Queue

type Queue[T any] struct {
	// contains filtered or unexported fields
}

Queue is a modified queue implementation duplicate of the queue design principles described in https://github.com/ef-ds/queue.

type StreamOutput

type StreamOutput struct {
	Output string
	Error  string
	Time   int64
}

type SystemUsers

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

SystemUsers represents a pool of users.

func NewSystemUsers

func NewSystemUsers(amount uint32) *SystemUsers

NewSystemUser creates a new pool of users with a specific amount. By default all users are free.

func (*SystemUsers) Acquire

func (su *SystemUsers) Acquire() (*User, error)

Acquire returns a free user and marks it as used. If no user was found, it will return an error.

func (SystemUsers) GetUsers

func (su SystemUsers) GetUsers() []*User

GetUsers returns the list of users in the current pool.

func (*SystemUsers) Release

func (su *SystemUsers) Release(uid uint32)

Release marks a user with the specified `uid“ as free.

type TestOutput

type TestOutput struct {
	Results []TestResult `json:"results" binding:"required"`
	Time    int64        `json:"time" binding:"required"`
}

type TestResult

type TestResult struct {
	Name     string   `json:"name"`
	Received string   `json:"received"`
	Actual   string   `json:"actual"`
	Stdin    []string `json:"stdin"`
	Passed   bool     `json:"passed"`
	RunError string   `json:"runError"`
}

type User

type User struct {
	Uid uint32
	// Free indicates a flag whether the user is free or not.
	Free     bool
	Username string
}

type WorkData

type WorkData struct {
	Lang        string
	Code        string
	Stdin       []string
	Tests       []TestResult
	BypassCache bool
}

type WorkType

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

WorkType represents a unit of work to be executed by the worker pool.

type WorkerPool

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

func NewWorkerPool

func NewWorkerPool(nWorkers int) *WorkerPool

NewWorkerPool creates a new worker pool instance with the specific number of worker goroutines.

func (*WorkerPool) SubmitJob

func (wp *WorkerPool) SubmitJob(data WorkData, action actionFunc, actionOutput ActionOutput, terminate chan<- bool)

SubmitJob adds a new work unit to the worker pool.

Jump to

Keyboard shortcuts

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