worker

package
v0.0.0-...-e258396 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package worker manages the execution and queue of tasks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection

type Connection interface {
	SendProAttachment(proToken string) error
	SendLandscapeConfig(lpeConfig, hostagentUID string) error
	Close()
}

Connection encapsulates the logic behind sending and receiving messages with the WSL-Pro-Service.

type Worker

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

Worker contains all the logic around task queueing and execution for one particular distro.

func New

func New(ctx context.Context, d distro, storageDir string) (w *Worker, err error)

New creates a new worker and starts it. Call Stop when you're done to avoid leaking the task execution goroutine.

func (*Worker) Connection

func (w *Worker) Connection() Connection

Connection returns the client to the WSL task service. Connection returns nil when no connection is set up.

func (*Worker) EnqueueDeferredTasks

func (w *Worker) EnqueueDeferredTasks()

EnqueueDeferredTasks takes all deferred tasks and promotes them to regular tasks.

func (*Worker) IsActive

func (w *Worker) IsActive() bool

IsActive returns true when the worker is running, and there exists an active connection to its GRPC service.

func (*Worker) SetConnection

func (w *Worker) SetConnection(conn Connection)

SetConnection removes the connection associated with the distro.

func (*Worker) Stop

func (w *Worker) Stop(ctx context.Context)

Stop stops the main task processing goroutine and wait for it to be done.

func (*Worker) SubmitDeferredTasks

func (w *Worker) SubmitDeferredTasks(tasks ...task.Task) (err error)

SubmitDeferredTasks takes one or more tasks into our current worker list.

The task(s) won't wake up the distro, instead wait until it is awake. This does NOT necessarily mean it'll run after non-deferred tasks.

It will return an error if the distro has been cleaned up.

func (*Worker) SubmitTasks

func (w *Worker) SubmitTasks(tasks ...task.Task) (err error)

SubmitTasks enqueues one or more task on our current worker list. The task will wake up the distro and be performed as soon as it reaches the beginning of the queue.

It will return an error if the distro has been cleaned up or the task queue is full.

Jump to

Keyboard shortcuts

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