util

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendFile added in v0.22.0

func AppendFile(path string, data []byte) error

func CreateDockerConnector

func CreateDockerConnector(org, id string, args ...interface{}) *harness.Connector

CreateDockerConnector helper function to create a docker connector

func CreateFolder added in v0.22.0

func CreateFolder(path string) error

func CreateGithubConnector

func CreateGithubConnector(org, id, username, token string) *harness.Connector

CreateGithubConnector helper function to create a github connector

func CreateGitlabConnector

func CreateGitlabConnector(org, id, username, token string) *harness.Connector

CreateGitlabConnector helper function to create a GitHub connector

func CreateSecret

func CreateSecret(org, project, identifier, desc, data string) *harness.Secret

func CreateSecretOrg

func CreateSecretOrg(org, identifier, data string) *harness.Secret

CreateSecretOrg helper function to create an org secret.

func DeleteDirsExcept added in v0.22.0

func DeleteDirsExcept(rootPath, exceptFilePath string) error

DeleteDirsExcept deletes all directories in the specified path except for the specified file's path.

func GetJson added in v0.22.0

func GetJson(data any) ([]byte, error)

func GetRepoDirFromRepoSlug added in v0.26.0

func GetRepoDirFromRepoSlug(repoSlug string) string

func IsErrConflict

func IsErrConflict(err error) bool

IsErrConflict helper function return true if the codeerror message indicate the resource already exists.

func JoinPaths added in v0.22.0

func JoinPaths(elem ...string) string

Join joins any number of path elements into a single path, separating them with slashes. Empty elements are ignored.

func Unzip added in v0.22.0

func Unzip(src string, dest string) error

func WriteFile added in v0.22.0

func WriteFile(path string, prJson []byte) error

func ZipFolder added in v0.22.0

func ZipFolder(source, destination string) error

ZipFolder zips the contents of the specified folder and saves the zip file to the specified destination.

Types

type DockerConnectorOptions

type DockerConnectorOptions struct {
	Username string
	Password string
	URL      string
}

type Result added in v0.22.0

type Result struct {
	ID   int
	Data any
	Err  error
}

Result represents the result of a task.

type Task added in v0.22.0

type Task struct {
	ID      int
	Execute func(ctx context.Context) (any, error)
}

Task represents a task to be executed.

type TaskPool added in v0.22.0

type TaskPool struct {
	MaxParallelism int
	TaskCh         chan *Task
	ResultCh       chan *Result
	Wg             *sync.WaitGroup

	Cancel context.CancelFunc
	// contains filtered or unexported fields
}

TaskPool represents a pool of workers that can execute tasks concurrently.

func NewTaskPool added in v0.22.0

func NewTaskPool(ctx context.Context, maxParallelism int) *TaskPool

NewTaskPool creates a new job pool.

func (*TaskPool) ForceShutdown added in v0.23.0

func (tp *TaskPool) ForceShutdown()

func (*TaskPool) MarkResultRead added in v0.22.0

func (tp *TaskPool) MarkResultRead()

func (*TaskPool) Shutdown added in v0.22.0

func (tp *TaskPool) Shutdown()

Shutdown gracefully shuts down the thread pool

func (*TaskPool) Start added in v0.22.0

func (tp *TaskPool) Start() error

Start starts the thread pool with the specified number of workers.

func (*TaskPool) Submit added in v0.22.0

func (tp *TaskPool) Submit(task *Task)

Submit submits a task to the thread pool.

type Worker added in v0.22.0

type Worker struct {
	ID       int
	TaskCh   chan *Task
	ResultCh chan *Result
	Wg       *sync.WaitGroup
}

Worker represents a worker that executes tasks.

func NewWorker added in v0.22.0

func NewWorker(id int, taskCh chan *Task, resultCh chan *Result, Wg *sync.WaitGroup) *Worker

NewWorker creates a new worker.

func (*Worker) Start added in v0.22.0

func (w *Worker) Start(ctx context.Context) error

Start starts the worker to listen for tasks and execute them.

Jump to

Keyboard shortcuts

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