{"modulePath":"github.com/programme-lv/backend","version":"v1.3.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package exec\n\n## Constants\n\n```go\nconst (\n\tReceivedSubmissionType  = \"received_submission\"\n\tStartedCompilationType  = \"started_compilation\"\n\tFinishedCompilationType = \"finished_compilation\"\n\tCompilationErrorType    = \"compilation_error\"\n\tReachedTestType         = \"reached_test\"\n\tIgnoredTestType         = \"ignored_test\"\n\tFinishedTestType        = \"finished_test\"\n\tFinishedTestingType     = \"finished_testing\"\n\tInternalServerErrorType = \"internal_server_error\"\n)\n```\n\n```go\nconst ErrCodeCheckerTooLarge = \"checker_too_large\"\n```\n\n```go\nconst ErrCodeConstraintTooLose = \"constraint_too_loose\"\n```\n\n```go\nconst ErrCodeEvalNotFound = \"eval_not_found\"\n```\n\n```go\nconst ErrCodeInteractorTooLarge = \"interactor_too_large\"\n```\n\n```go\nconst ErrCodeInvalidTestFile = \"invalid_test_file\"\n```\n\n```go\nconst ErrCodeInvalidTesterParams = \"invalid_tester_params\"\n```\n\n```go\nconst ErrCodeMemConstraintTooLose = \"mem_constraint_too_loose\"\n```\n\n```go\nconst ErrCodeTooManyTests = \"too_many_tests\"\n```\n\n```go\nconst NatsSubject = \"tester.jobs\"\n```\n\n## Variables\n\n```go\nvar ErrCheckerTooLarge = srvcerror.New(\n\tErrCodeCheckerTooLarge,\n\t\"Checker program too large\",\n).SetHttpStatusCode(http.StatusBadRequest)\n```\n\n```go\nvar ErrCpuConstraintTooLose = srvcerror.New(\n\tErrCodeConstraintTooLose,\n\t\"CPU time limit too long\",\n).SetHttpStatusCode(http.StatusBadRequest)\n```\n\n```go\nvar ErrEvalNotFound = srvcerror.New(\n\tErrCodeEvalNotFound,\n\t\"Evaluation not found\",\n).SetHttpStatusCode(http.StatusNotFound)\n```\n\n```go\nvar ErrInteractorTooLarge = srvcerror.New(\n\tErrCodeInteractorTooLarge,\n\t\"Interactor program too large\",\n).SetHttpStatusCode(http.StatusBadRequest)\n```\n\n```go\nvar ErrInvalidTestFile = srvcerror.New(\n\tErrCodeInvalidTestFile,\n\t\"Invalid test file\",\n).SetHttpStatusCode(http.StatusBadRequest)\n```\n\n```go\nvar ErrInvalidTesterParams = srvcerror.New(\n\tErrCodeInvalidTesterParams,\n\t\"invalid tester parameters\",\n).SetHttpStatusCode(http.StatusBadRequest)\n```\n\n```go\nvar ErrMemConstraintTooLose = srvcerror.New(\n\tErrCodeMemConstraintTooLose,\n\t\"Memory limit too large\",\n).SetHttpStatusCode(http.StatusBadRequest)\n```\n\n```go\nvar ErrTooManyTests = srvcerror.New(\n\tErrCodeTooManyTests,\n\t\"Too many tests\",\n).SetHttpStatusCode(http.StatusBadRequest)\n```\n\n## Functions\n\n```go\nfunc NewExecSrvc(ctx context.Context, repo ExecRepo, natsConn *nats.Conn, testfileStore TestFileStore) *execSrvc\n```\n\n## Types\n\n```go\ntype CodeExecutionService interface {\n\tEnqueue(ctx context.Context, uuid uuid.UUID, srcCode string, prLangId string, tests []TestFile, params TestingParams) srvcerror.E\n\tListen(ctx context.Context, uuid uuid.UUID) (\u003c-chan Event, srvcerror.E)\n\tGet(ctx context.Context, execUuid uuid.UUID) (Execution, srvcerror.E)\n}\n```\n\n```go\ntype CodeWithLang struct {\n\tSrcCode string // user submitted solution source code\n\tLangId  string // short compiler, interpreter id\n}\n```\nuser submitted solution\n\n```go\ntype CompilationError struct {\n\tErrorMsg *string `json:\"error_msg\"`\n}\n```\n\n```go\nfunc (s CompilationError) MarshalJSON() ([]byte, error)\n```\n\n```go\nfunc (s CompilationError) Type() string\n```\n\n```go\ntype Event interface {\n\tType() string\n\tMarshalJSON() ([]byte, error)\n}\n```\n\n```go\ntype ExecRepo interface {\n\tSave(ctx context.Context, exec *Execution) error\n\tGet(ctx context.Context, id uuid.UUID) (*Execution, error)\n}\n```\nExecRepo interface for execution storage\n\n```go\ntype ExecRequest struct {\n\tUUID  uuid.UUID\n\tCode  string\n\tLang  PrLang\n\tTests []TestFile\n\n\tCpuMs  int `json:\"cpu_ms\"`  // max user-mode CPU time in milliseconds\n\tMemKiB int `json:\"mem_kib\"` // max resident set size in kibibytes\n\n\t// optional testlib.h checker program. If not provided,\n\t// only output of the user's solution is returned from tester\n\t// and is not viable for grading. \"run program\" use case.\n\tChecker *string `json:\"checker\"`\n\n\t// optional testlib.h interactor program.\n\tInteractor *string `json:\"interactor\"`\n}\n```\n\n```go\nfunc (e ExecRequest) IsValid() error\n```\n\n```go\nfunc (e ExecRequest) MapToTesterApiType() *testerapi.ExecReq\n```\n\n```go\ntype ExecResStreamOrganizer struct {\n\t// contains filtered or unexported fields\n}\n```\nExecResStreamOrganizer processes and orders a stream of testing events to ensure:\n\n  - Sequential ordering: Events are emitted only after their dependencies are satisfied\n  - Deduplication: Events with identical keys are processed only once\n  - Completeness: All required events must be received before testing completion\n\nThe organizer supports concurrent test execution while maintaining sequential event emission. For example, if test #2 finishes before test #1, the organizer will buffer test #2's results until test #1's results are processed.\n\n```go\nfunc (o *ExecResStreamOrganizer) Add(\n\tevent Event,\n) ([]Event, error)\n```\nAdd processes an incoming event and returns any events that are now ready for emission. Events are considered ready when all their dependencies have been satisfied and emitted. For example:\n\n  - Test results require their \"test reached\" event\n  - Tests require compilation success if compiled\n\nHandles deduplication and sequential ordering. Returns error if event type is unknown.\n\n```go\nfunc (o *ExecResStreamOrganizer) HasFinished() bool\n```\nHasFinished indicates whether evaluation has completed and no more events will be processed. This occurs when:\n\n  - Internal server error encountered\n  - All tests complete successfully\n  - Compilation fails\n\n```go\ntype ExecStage string\n```\n\n```go\nconst (\n\tStageWaiting       ExecStage = \"waiting\"\n\tStageCompiling     ExecStage = \"compiling\"\n\tStageTesting       ExecStage = \"testing\"\n\tStageFinished      ExecStage = \"finished\"\n\tStageCompileError  ExecStage = \"compile_error\"\n\tStageInternalError ExecStage = \"internal_error\"\n)\n```\n\n```go\ntype Execution struct {\n\tUUID      uuid.UUID     `json:\"uuid\"`\n\tStage     ExecStage     `json:\"stage\"`\n\tTestRes   []TestRes     `json:\"test_res\"`\n\tPrLang    PrLang        `json:\"pr_lang\"`\n\tParams    TestingParams `json:\"params\"`\n\tErrorMsg  *string       `json:\"error_msg\"`\n\tSysInfo   *string       `json:\"sys_info\"` // testing hardware info\n\tCreatedAt time.Time     `json:\"created_at\"`\n\tSubmComp  *RunData      `json:\"subm_comp\"` // submitted code compilation runtime data\n\n}\n```\n\n```go\nfunc (e *Execution) SimilarTo(other Execution) error\n```\nDoes not compare UUID, SysInfo, CreatedAt Ensures that execution time deviations are within reasonable deviations\n\n```go\ntype FileEvalRepo struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewFileExecRepo(ctx context.Context, store *filestore.Store) *FileEvalRepo\n```\n\n```go\nfunc (r *FileEvalRepo) Get(ctx context.Context, evalUuid uuid.UUID) (*Execution, error)\n```\n\n```go\nfunc (r *FileEvalRepo) Save(ctx context.Context, eval *Execution) error\n```\n\n```go\ntype FinishedCompiling struct {\n\tRuntimeData *RunData `json:\"runtime_data\"`\n}\n```\n\n```go\nfunc (s FinishedCompiling) MarshalJSON() ([]byte, error)\n```\n\n```go\nfunc (s FinishedCompiling) Type() string\n```\n\n```go\ntype FinishedTest struct {\n\tTestID  int      `json:\"test_id\"`\n\tSubm    *RunData `json:\"submission\"`\n\tChecker *RunData `json:\"checker\"`\n}\n```\n\n```go\nfunc (s FinishedTest) MarshalJSON() ([]byte, error)\n```\n\n```go\nfunc (s FinishedTest) Type() string\n```\n\n```go\ntype FinishedTesting struct{}\n```\n\n```go\nfunc (s FinishedTesting) MarshalJSON() ([]byte, error)\n```\n\n```go\nfunc (s FinishedTesting) Type() string\n```\n\n```go\ntype IgnoredTest struct {\n\tTestId int `json:\"test_id\"`\n}\n```\n\n```go\nfunc (s IgnoredTest) MarshalJSON() ([]byte, error)\n```\n\n```go\nfunc (s IgnoredTest) Type() string\n```\n\n```go\ntype InMemExecRepo struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewInMemExecRepo() *InMemExecRepo\n```\n\n```go\nfunc (i *InMemExecRepo) Get(ctx context.Context, id uuid.UUID) (*Execution, error)\n```\nGet implements [ExecRepo](#ExecRepo).\n\n```go\nfunc (i *InMemExecRepo) Save(ctx context.Context, exec *Execution) error\n```\nSave implements [ExecRepo](#ExecRepo).\n\n```go\ntype InternalServerError struct {\n\tErrorMsg *string `json:\"error_msg\"`\n}\n```\n\n```go\nfunc (s InternalServerError) MarshalJSON() ([]byte, error)\n```\n\n```go\nfunc (s InternalServerError) Type() string\n```\n\n```go\ntype PrLang struct {\n\tShortId   string  `json:\"short_id\"`   // short lang/compiler/interpreter id\n\tDisplay   string  `json:\"display\"`    // user-friendly programming lang name\n\tCodeFname string  `json:\"code_fname\"` // source code filename for mv in to box\n\tCompCmd   *string `json:\"comp_cmd\"`   // compile command\n\tCompFname *string `json:\"comp_fname\"` // exe fname after comp for mv out of box\n\tExecCmd   string  `json:\"exec_cmd\"`   // execution command\n}\n```\n\n```go\ntype ReachedTest struct {\n\tTestId int     `json:\"test_id\"`\n\tIn     *string `json:\"in\"`\n\tAns    *string `json:\"ans\"`\n}\n```\n\n```go\nfunc (s ReachedTest) MarshalJSON() ([]byte, error)\n```\n\n```go\nfunc (s ReachedTest) Type() string\n```\n\n```go\ntype ReceivedSubmission struct {\n\tSysInfo   string    `json:\"sys_info\"`\n\tStartedAt time.Time `json:\"started_at\"`\n}\n```\n\n```go\nfunc (s ReceivedSubmission) MarshalJSON() ([]byte, error)\n```\n\n```go\nfunc (s ReceivedSubmission) Type() string\n```\n\n```go\ntype RunData struct {\n\tStdIn       string  `json:\"in\"`            // standard input\n\tStdOut      string  `json:\"out\"`           // standard output\n\tStdErr      string  `json:\"err\"`           // standard error\n\tCpuMs       int64   `json:\"cpu_ms\"`        // cpu user-mode time in milliseconds\n\tWallMs      int64   `json:\"wall_ms\"`       // wall clock time in milliseconds\n\tMemKiB      int64   `json:\"mem_kib\"`       // memory usage (resident set size) in kibibytes\n\tExitCode    int64   `json:\"exit\"`          // exit code\n\tCtxSwV      int64   `json:\"ctx_sw_v\"`      // voluntary context switches, e.g. waiting for I/O\n\tCtxSwF      int64   `json:\"ctx_sw_f\"`      // involuntary context switches, e.g. waiting for CPU\n\tSignal      *int64  `json:\"signal\"`        // exit signal if any\n\tIsOomKilled bool    `json:\"is_oom_killed\"` // whether the process was killed due to memory exhaustion\n\tIsolStatus  *string `json:\"isol_status\"`   // isolate sandbox execution environment status\n\tIsolMsg     *string `json:\"isol_msg\"`      // isolate sandbox execution environment message\n}\n```\nRuntime Data\n\n```go\nfunc (r *RunData) SimilarTo(other RunData) error\n```\n\n```go\ntype StartedCompiling struct{}\n```\n\n```go\nfunc (s StartedCompiling) MarshalJSON() ([]byte, error)\n```\n\n```go\nfunc (s StartedCompiling) Type() string\n```\n\n```go\ntype TestFile struct {\n\tInSha256   *string // SHA256 hash of input for caching\n\tInDownlUrl *string // URL to download input\n\tInContent  *string // input content as alternative to URL\n\n\tAnsSha256   *string // SHA256 hash of answer for caching\n\tAnsDownlUrl *string // URL to download answer\n\tAnsContent  *string // answer content as alternative to URL\n}\n```\ninput and expected output\n\n```go\nfunc (t *TestFile) IsValid() error\n```\n\n```go\ntype TestFileStore interface {\n\tOpen(key string) (io.ReadCloser, error)\n}\n```\n\n```go\ntype TestRes struct {\n\tID       int     `json:\"id\"`\n\tInput    *string `json:\"inp\"` // trimmed test input file preview\n\tAnswer   *string `json:\"ans\"` // trimmed test answer file preview\n\tReached  bool    `json:\"rch\"`\n\tIgnored  bool    `json:\"ign\"` // when score group has another failed test\n\tFinished bool    `json:\"fin\"`\n\n\tSubm    *RunData `json:\"subm_rd\"` // user submitted solution\n\tChecker *RunData `json:\"tlib_rd\"` // testlib checker\n}\n```\n\n```go\nfunc (t *TestRes) SimilarTo(other TestRes) error\n```\n\n```go\ntype TestingParams struct {\n\tCpuMs  int `json:\"cpu_ms\"`  // maximum user-mode CPU time in milliseconds\n\tMemKiB int `json:\"mem_kib\"` // maximum resident set size in kibibytes\n\n\t// optional testlib.h checker program. If not provided,\n\t// only output of the user's solution is returned from tester\n\t// and is not viable for grading. \"run program\" use case.\n\tChecker *string `json:\"checker\"`\n\n\t// optional testlib.h interactor program.\n\tInteractor *string `json:\"interactor\"`\n}\n```\nTester machine submitted solution runtime constraints\n\n```go\nfunc (p *TestingParams) IsValid() error\n```\n\n","path":"github.com/programme-lv/backend/modules/exec","name":"exec","synopsis":"","isRedistributable":true}
