Use groups
Put what a script deploys into a group, so it can find it again and tear it down without its own bookkeeping, and share members (a schedule, a feed) between groups. The rules are in Groups.
Create a group and deploy into it
Python (virtufin-workmanager):
from virtufin.workmanager import WorkManagerClient
async with WorkManagerClient(host, port) as wm:
group = await wm.create_group(tags={"name": "Momentum BTC", "managed-by": "rebalance-notebook"})
worker = await wm.create_worker({"url": nupkg_url}, "application/x-dotnet-dll", [topic], groups=[group])
await wm.start_worker(worker)
C# (GatewayWorkManagerClient):
var group = await workManager.CreateGroupAsync(new GroupSpec(Tags: new Dictionary<string, string>
{
["name"] = "Momentum BTC",
["managed-by"] = "rebalance-notebook",
}));
var worker = await workManager.CreateWorkerAsync(spec with { Groups = [group] });
The group's id is a generated UUID. Give one only when the id is derived by rule (a version 5 UUID
from a name, the same in every run): create_group(id=...) fails with ALREADY_EXISTS when that
group exists, so a duplicate never passes silently.
Find your group again
Tag it, and list by tag on the next run:
groups = await wm.list_groups(tag_filters={"managed-by": "rebalance-notebook"})
workers = await wm.list_workers(group=groups[0]["id"])
Share a member
Add a worker or a trigger to a second group; it now belongs to both:
await wm.add_to_group(other_group, workers=[worker], triggers=[every_minute])
remove_from_group takes a member out and never deletes it.
Nest groups
A group may sit under several parents. Owners are inherited through every parent; scopes are not.
sweep = await wm.create_group(tags={"name": "sweep A"}, owners=["user:alice"])
scenario = await wm.create_group(tags={"name": "S1"}, parents=[sweep], scopes=["sc.S1."])
assert "user:alice" in await wm.resolve_group_owners(scenario)
Tear it down
outcomes = await wm.delete_group(group, recursive=True)
Members in no other group are stopped and deleted; shared ones stay, running, and lose only this
membership; the answer lists each member's outcome. If a member fails, the call fails with
ABORTED, the group stays deleting, and calling delete_group again finishes it.