ctxt

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Copyright © 2020 Marvin

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(ctx context.Context, limit int, logger *printer.Logger) context.Context

New create a context instance.

Types

type Context

type Context struct {
	Mutex sync.RWMutex

	Ev EventBus

	Exec struct {
		Executors    map[string]executor.Executor
		Stdouts      map[string][]byte
		Stderrs      map[string][]byte
		CheckResults map[string][]interface{}
	}

	// Private key/public key is used to access the remote server through the user
	PrivateKeyPath string
	PublicKeyPath  string
	Concurrency    int // max number of parallel tasks running at the same time
}

Context is used to share state when multiple tasks are executed. Use Mutex locks to prevent concurrent reading/writing of certain fields Because the same context can be shared in parallel tasks.

func GetInner

func GetInner(ctx context.Context) *Context

GetInner return *Context from context.Context's value

func (*Context) Get

func (ctx *Context) Get(host string) (e executor.Executor)

Get implements the operation.ExecutorGetter interface.

func (*Context) GetCheckResults

func (ctx *Context) GetCheckResults(host string) (results []any, ok bool)

GetCheckResults get the the check result of a host (if has any)

func (*Context) GetExecutor

func (ctx *Context) GetExecutor(host string) (e executor.Executor, ok bool)

GetExecutor get the executor.

func (*Context) GetOutputs

func (ctx *Context) GetOutputs(hostID string) ([]byte, []byte, bool)

GetOutputs get the outputs of a host (if has any)

func (*Context) GetSSHKeySet

func (ctx *Context) GetSSHKeySet() (privateKeyPath, publicKeyPath string)

GetSSHKeySet implements the operation.ExecutorGetter interface.

func (*Context) SetCheckResults

func (ctx *Context) SetCheckResults(host string, results []any)

SetCheckResults append the check result of a host to the list

func (*Context) SetExecutor

func (ctx *Context) SetExecutor(host string, e executor.Executor)

SetExecutor set the executor.

func (*Context) SetOutputs

func (ctx *Context) SetOutputs(hostID string, stdout []byte, stderr []byte)

SetOutputs set the outputs of a host

type EventBus

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

EventBus is an event bus for task events.

func NewEventBus

func NewEventBus() EventBus

NewEventBus creates a new EventBus.

func (*EventBus) PublishTaskBegin

func (ev *EventBus) PublishTaskBegin(task fmt.Stringer)

PublishTaskBegin publishes a TaskBegin event. This should be called only by Parallel or Serial.

func (*EventBus) PublishTaskFinish

func (ev *EventBus) PublishTaskFinish(task fmt.Stringer, err error)

PublishTaskFinish publishes a TaskFinish event. This should be called only by Parallel or Serial.

func (*EventBus) PublishTaskProgress

func (ev *EventBus) PublishTaskProgress(task fmt.Stringer, progress string)

PublishTaskProgress publishes a TaskProgress event.

func (*EventBus) Subscribe

func (ev *EventBus) Subscribe(eventName EventKind, handler any)

Subscribe subscribes events.

func (*EventBus) Unsubscribe

func (ev *EventBus) Unsubscribe(eventName EventKind, handler any)

Unsubscribe unsubscribes events.

type EventKind

type EventKind string

EventKind is the task event kind.

const (
	// EventTaskBegin is emitted when a task is going to be executed.
	EventTaskBegin EventKind = "task_begin"
	// EventTaskFinish is emitted when a task finishes executing.
	EventTaskFinish EventKind = "task_finish"
	// EventTaskProgress is emitted when a task has made some progress.
	EventTaskProgress EventKind = "task_progress"
)

type ExecutorGetter

type ExecutorGetter interface {
	Get(host string) (e executor.Executor)
	// GetSSHKeySet gets the SSH private and public key path
	GetSSHKeySet() (privateKeyPath, publicKeyPath string)
}

ExecutorGetter get the executor by host.

Jump to

Keyboard shortcuts

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