Skip to content

Getting Started

This walkthrough takes the canonical HttpGetWorker worker from a clean checkout to a running worker on a local Virtufin stack.

Prerequisites

  • .NET 11 SDK
  • Python 3.11+ and the virtufin-worker CLI: pip install 'virtufin-dev[workers]' --extra-index-url https://pypi.haenerconsulting.com/api/packages/virtufin/pypi/simple/
  • Docker (with the docker.haenerconsulting.com/library/dotnet-crossbuild:11 image available locally for AOT builds)
  • A running API, WorkManager and WorkManager Runtime: deploy-local runs them on your machine, configured like the helm chart configures the cluster (the local WorkManager Runtime must reach the org feed)

1. Build the worker (managed)

git clone https://git.haenerconsulting.com/virtufin/platform-workers.git
cd platform-workers
virtufin-worker build HttpGet

This runs dotnet publish on the managed csproj; Worker.DevKit's VirtufinPackageWorker target writes the nupkg to build/HttpGet/, and the CLI writes build_version.txt next to it:

==> dotnet publish Virtufin.Worker.HttpGet.Managed.csproj (0.6.5)
==> Built .../build/HttpGet/Virtufin.Worker.HttpGet.nupkg (7,283 bytes), version 0.6.5

2. Publish the nupkg

virtufin-worker publish HttpGet

Uploads the nupkg to the Gitea NuGet feed (https://gitea.haenerconsulting.com/api/packages/virtufin/nuget/), with the credentials from the VIRTUFIN_REGISTRY_USER / VIRTUFIN_REGISTRY_TOKEN env vars, and refuses a version that is already there. CI does this on every push that bumps HttpGet/versions.env, so you rarely run it yourself.

3. Deploy and trigger it

virtufin-worker create HttpGet --context local

creates the worker from the feed and starts it. --context names an entry in ~/.config/virtufin/api/contexts.toml (the file virtufin-tui and the examples read). The request it sends, in Python: the feed is private, so the code source carries the named credential virtufin, which the WorkManager resolves server-side:

from virtufin.api import ApiClient

version = "0.6.5"  # LIBRARY_VERSION from HttpGet/versions.env
url = ("https://gitea.haenerconsulting.com/api/packages/virtufin/nuget/package/"
       f"virtufin.worker.httpget/{version}/virtufin.worker.httpget.{version}.nupkg")

async with ApiClient("localhost", 5002) as api:
    created = await api.gateway.workmanager.CreateWorker({
        "code_source": {"url": url, "credential": {"named": "virtufin"}},
        "mime_type": "application/x-dotnet-dll",
        "topics": ["wrk.httpget.command.{worker_id}"],  # the WorkManager fills in {worker_id}
    })
    worker_id = created["id"]
    await api.gateway.workmanager.StartWorker({"id": worker_id})

CreateWorker returns before the code is loaded; StartWorker takes effect once it is. The worker's progress is published on sys.workmanager.worker.lifecycle (registered, loaded, starting, online), and a load that fails publishes load-failed with the error. See Worker Lifecycle.

Trigger it by publishing a CloudEvent on its command topic wrk.httpget.command.<worker_id> whose data is {"url": "https://example.com/data"}:

from virtufin.api import ApiClient

async with ApiClient("localhost", 5002) as api:
    result = await api.pubsub.publish_with_result_async(
        topic=f"wrk.httpget.command.{worker_id}",
        data={"url": "https://example.com/data"},
        reply_topic="response.httpget",
        timeout=10.0,
    )
    print(result.data_as_json())

The worker performs the GET and publishes the response — datacontenttype mirrors the upstream response's own Content-Type, data is the body as text. See HttpGet for the full response shape and error handling.

4. (Optional) Add the NativeAOT layout

virtufin-worker build HttpGet --native

AOT-publishes the native csproj per RID in the cross-build image (Docker, clang + cross-binutils) and produces a single nupkg with lib/net11.0/HttpGetWorker.dll AND runtimes/<rid>/native/libHttpGetWorker.so. Create a worker from it with either MIME type (virtufin-worker create HttpGet --native --context local for application/x-native-dll).

Next steps