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
idGuidcodeSourceCodeSourcemimeTypestringengineIEnginetopicsIReadOnlyList<string>createdAtDateTimeloggerILogger<Worker>historyList<HistoryEntry>configIDictionary<string, string>tagsIDictionary<string, string>
Properties
CodeSource
The source of the worker's code.
public CodeSource CodeSource { get; }
Property Value
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
CreatedAt
The timestamp when this worker was created.
public DateTime CreatedAt { get; }
Property Value
History
The history of code changes for this worker.
public List<HistoryEntry> History { get; }
Property Value
Id
The unique identifier of this worker.
public Guid Id { get; }
Property Value
MimeType
The MIME type of the worker's code.
public string MimeType { get; }
Property Value
Status
The current status of the worker.
public WorkerStatus Status { get; set; }
Property Value
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
Topics
The topics this worker subscribes to (one or more).
public IReadOnlyList<string> Topics { get; }
Property Value
Methods
LoadCodeAsync(byte[], CancellationToken)
Loads code into the worker's engine.
public Task LoadCodeAsync(byte[] blob, CancellationToken cancellationToken = default)
Parameters
blobbyte[]The code blob to load.
cancellationTokenCancellationTokenCancellation token.
Returns
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
inputCloudEventThe incoming cloud event.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<CloudEvent>
The response cloud event, or
nullif 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
SetTags(IDictionary<string, string>)
Replaces the entire tag set with the provided dictionary.
public void SetTags(IDictionary<string, string> tags)
Parameters
tagsIDictionary<string, string>