Files
hatchet/examples/python/runtime_affinity/worker.py
matt 6c29e48204 Feat: Dynamic worker label assign (#3137)
* feat: initial wiring work on desired labels

* feat: initial wiring

* chore: gen python

* fix: use the whole desired label thing instead

* fix: more wiring, improve types

* fix: sql type

* fix: len check

* chore: gen python

* fix: initial plural label work

* fix: store the labels properly on the task

* fix: skip cache on override

* fix: bug

* fix: scoping bug whoops

* chore: lint

* fix: send labels back over the api correctly

* feat: python test

* fix: lint

* fix: comment

* fix: override

* fix: namespaces, ugh

* fix: no need for error here

* chore: version

* feat: ruby, go, ts

* feat: versions

* fix: appease the rubocop

* chore: lint

* chore: bundle install

* fix: tests

* chore: lint

* chore: lint more

* fix: ts test

* fix: rb

* chore: gen

* chore: reset gemfile

* chore: reset changelog

* fix: pgroup

* fix: tests, part i

* Revert "chore: reset changelog"

This reverts commit b63bf7d3e5.

* Revert "chore: reset gemfile"

This reverts commit bb848bb6f0.

* fix: go -> golang mapping hack

* fix: go enums

* fix: appease the cop

* fix: namespace

* chore: gen
2026-03-04 11:03:58 -05:00

34 lines
698 B
Python

import argparse
from hatchet_sdk import Context, EmptyModel, Hatchet
from pydantic import BaseModel
hatchet = Hatchet(debug=True)
class AffinityResult(BaseModel):
worker_id: str
@hatchet.task()
async def affinity_example_task(i: EmptyModel, c: Context) -> AffinityResult:
return AffinityResult(worker_id=c.worker_id)
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("--label", type=str, required=True)
args = parser.parse_args()
worker = hatchet.worker(
"runtime-affinity-worker",
labels={"affinity": args.label},
workflows=[affinity_example_task],
)
worker.start()
if __name__ == "__main__":
main()