package worker

import "github.com/redhatinsights/yggdrasil/worker"

Index

Types

type CancelRxFunc

type CancelRxFunc func(w *Worker, addr string, id string, cancelID string) error

CancelRxFunc is a function type that gets called each time the worker receives a cancel message

type EventHandlerFunc

type EventHandlerFunc func(e ipc.DispatcherEvent)

EventHandlerFunc is a function type that gets called each time the worker receives a com.redhat.Yggdrasil1.Dispatcher1.Event signal.

type RxFunc

type RxFunc func(w *Worker, addr string, id string, responseTo string, metadata map[string]string, data []byte) error

RxFunc is a function type that gets called each time the worker receives data.

type Worker

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

Worker implements the com.redhat.Yggdrasil1.Worker1 interface.

func NewWorker

func NewWorker(
	directive string,
	remoteContent bool,
	features map[string]string,
	cancel CancelRxFunc,
	rx RxFunc,
	events EventHandlerFunc,
) (*Worker, error)

NewWorker creates a new worker.

func (*Worker) Connect

func (w *Worker) Connect(quit <-chan os.Signal) error

Connect connects to the bus, exports the worker on its object path, and requests a well-known bus name. It connects to a private session bus, if DBUS_SESSION_BUS_ADDRESS is set in the environment. Otherwise it connects to the system bus. It exports w onto the bus and waits until a signal is received on quit.

func (*Worker) EmitEvent

func (w *Worker) EmitEvent(
	event ipc.WorkerEventName,
	messageID string,
	responseTo string,
	data map[string]string,
) error

EmitEvent emits a WorkerEvent, worker message id, and key-value pairs of optional data.

func (*Worker) GetFeature

func (w *Worker) GetFeature(name string) string

GetFeature retrieves the value from the feature map for given key.

func (*Worker) SetFeature

func (w *Worker) SetFeature(name, value string) error

SetFeature sets the value for the given key in the feature map and emits the PropertiesChanged signal.

func (*Worker) Transmit

func (w *Worker) Transmit(
	addr string,
	id string,
	responseTo string,
	metadata map[string]string,
	data []byte,
) (responseCode int, responseMetadata map[string]string, responseData []byte, err error)

Transmit wraps a com.redhat.Yggdrasil1.Dispatcher1.Transmit method call for ease of use from the worker.

Source Files

worker.go

Directories

PathSynopsis
worker/echo
Version
v0.4.5 (latest)
Published
Feb 3, 2025
Platform
linux/amd64
Imports
9 packages
Last checked
3 weeks ago

Tools for package owners.