mirror of
https://github.com/ultravioletrs/cocos.git
synced 2026-08-07 07:14:50 +00:00
22c14cb438
CI / lint (push) Has been cancelled
CI / checkproto (push) Has been cancelled
CI / test (agent) (push) Has been cancelled
CI / upload-coverage (push) Has been cancelled
CI / test (cli) (push) Has been cancelled
CI / test (cmd) (push) Has been cancelled
CI / test (internal) (push) Has been cancelled
CI / test (manager, true) (push) Has been cancelled
CI / test (pkg) (push) Has been cancelled
* Update protobuf generated files and improve algorithm handling in runner service - Bump protoc version from v7.35.0 to v7.35.1 in generated protobuf files. - Refactor RunRequest message in runner.proto to use string paths for algorithm and requirements instead of byte arrays. - Update runner service to handle algorithm and requirements paths, removing the need for temporary file creation. - Enhance error handling for missing algorithm paths in the runner service. - Modify tests to align with the new RunRequest structure and ensure proper file handling. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * chore: update protoc version to 35.1 in CI workflow Signed-off-by: Sammy Oina <sammyoina@gmail.com> * feat: update systemd service configurations and dependencies for improved service management Signed-off-by: Sammy Oina <sammyoina@gmail.com> * fix: adjust AlgoWorkingDir handling in tests for Docker algorithm Signed-off-by: Sammy Oina <sammyoina@gmail.com> --------- Signed-off-by: Sammy Oina <sammyoina@gmail.com>
56 lines
1.5 KiB
Go
56 lines
1.5 KiB
Go
// Copyright (c) Ultraviolet
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
package algorithm
|
|
|
|
import (
|
|
"context"
|
|
|
|
"google.golang.org/grpc/metadata"
|
|
)
|
|
|
|
type AlgorithType string
|
|
|
|
const (
|
|
AlgoTypeBin AlgorithType = "bin"
|
|
AlgoTypePython AlgorithType = "python"
|
|
AlgoTypeWasm AlgorithType = "wasm"
|
|
AlgoTypeDocker AlgorithType = "docker"
|
|
AlgoTypeKey = "algo_type"
|
|
AlgoArgsKey = "algo_args"
|
|
|
|
ResultsDir = "results"
|
|
DatasetsDir = "datasets"
|
|
)
|
|
|
|
// AlgoWorkingDir is the base directory used by algorithm runners (e.g. docker)
|
|
// to create datasets/results mounts. It is a variable so tests can override it.
|
|
var AlgoWorkingDir = "/cocos"
|
|
|
|
func AlgorithmTypeToContext(ctx context.Context, algoType string) context.Context {
|
|
return metadata.AppendToOutgoingContext(ctx, AlgoTypeKey, algoType)
|
|
}
|
|
|
|
func AlgorithmTypeFromContext(ctx context.Context) string {
|
|
return metadata.ValueFromIncomingContext(ctx, AlgoTypeKey)[0]
|
|
}
|
|
|
|
func AlgorithmArgsToContext(ctx context.Context, algoArgs []string) context.Context {
|
|
for _, arg := range algoArgs {
|
|
ctx = metadata.AppendToOutgoingContext(ctx, AlgoArgsKey, arg)
|
|
}
|
|
return ctx
|
|
}
|
|
|
|
func AlgorithmArgsFromContext(ctx context.Context) []string {
|
|
return metadata.ValueFromIncomingContext(ctx, AlgoArgsKey)
|
|
}
|
|
|
|
// Algorithm is an interface that specifies the API for an algorithm.
|
|
type Algorithm interface {
|
|
// Run executes the algorithm and returns the result.
|
|
Run() error
|
|
|
|
// Stop stops the algorithm.
|
|
Stop() error
|
|
}
|