Table of Contents

Class Worker

Namespace
Virtufin.WorkManager.Runtime
Assembly
Virtufin.WorkManager.dll

Represents a worker instance that processes cloud events using an engine.

public sealed class Worker
Inheritance
Worker
Inherited Members

Constructors

Worker(Guid, CodeSource, string, IEngine, IReadOnlyList<string>, DateTime, ILogger<Worker>, List<HistoryEntry>?, IDictionary<string, string>?, IDictionary<string, string>?)

Creates a new worker instance.

public Worker(Guid id, CodeSource codeSource, string mimeType, IEngine engine, IReadOnlyList<string> topics, DateTime createdAt, ILogger<Worker> logger, List<HistoryEntry>? history = null, IDictionary<string, string>? config = null, IDictionary<string, string>? tags = null)

Parameters

id Guid
codeSource CodeSource
mimeType string
engine IEngine
topics IReadOnlyList<string>
createdAt DateTime
logger ILogger<Worker>
history List<HistoryEntry>
config IDictionary<string, string>
tags IDictionary<string, string>

Properties

CodeSource

The source of the worker's code.

public CodeSource CodeSource { get; }

Property Value

CodeSource

Config

Read-only view of the worker's creation-time config. Immutable for the lifetime of the worker — set once via the constructor, no setters. Stamped onto every incoming CloudEvent as extension attributes by ProcessAsync(CloudEvent, CancellationToken).

public IReadOnlyDictionary<string, string> Config { get; }

Property Value

IReadOnlyDictionary<string, string>

CreatedAt

The timestamp when this worker was created.

public DateTime CreatedAt { get; }

Property Value

DateTime

History

The history of code changes for this worker.

public List<HistoryEntry> History { get; }

Property Value

List<HistoryEntry>

Id

The unique identifier of this worker.

public Guid Id { get; }

Property Value

Guid

MimeType

The MIME type of the worker's code.

public string MimeType { get; }

Property Value

string

Status

The current status of the worker.

public WorkerStatus Status { get; set; }

Property Value

WorkerStatus

Tags

Read-only view of the worker's currently-set tags (resource metadata). Mutate via SetTag(string, string) or SetTags(IDictionary<string, string>).

public IReadOnlyDictionary<string, string> Tags { get; }

Property Value

IReadOnlyDictionary<string, string>

Topics

The topics this worker subscribes to (one or more).

public IReadOnlyList<string> Topics { get; }

Property Value

IReadOnlyList<string>

Methods

LoadCodeAsync(byte[], CancellationToken)

Loads code into the worker's engine.

public Task LoadCodeAsync(byte[] blob, CancellationToken cancellationToken = default)

Parameters

blob byte[]

The code blob to load.

cancellationToken CancellationToken

Cancellation token.

Returns

Task

ProcessAsync(CloudEvent, CancellationToken)

Processes a cloud event through the worker's engine. The worker's creation-time Config entries are stamped onto input as CloudEvent extension attributes first, giving the worker a per-instance default it can fall back to when the event's own payload doesn't specify a value.

public Task<CloudEvent?> ProcessAsync(CloudEvent input, CancellationToken cancellationToken = default)

Parameters

input CloudEvent

The incoming cloud event.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<CloudEvent>

The response cloud event, or null if no response.

SetTag(string, string)

Sets or replaces a single tag for this worker. Tags are resource metadata and are NOT injected into the engine process.

public void SetTag(string key, string value)

Parameters

key string
value string

SetTags(IDictionary<string, string>)

Replaces the entire tag set with the provided dictionary.

public void SetTags(IDictionary<string, string> tags)

Parameters

tags IDictionary<string, string>