mvgijssel
mvgijssel4w ago

Is it possible to use the custom_tags endpoint using the API?

I'm currently working on a use case which spins up a worker with a unique identifier in the tags list and I'm wondering if there is a way to use the API to register this custom tag in Windmill using the custom tags endpoint. Developing using the UI I see that the http://localhost/api/settings/global/custom_tags endpoint is used for registering tags, but I don't see the endpoint listed in OpenAPI documentation https://app.windmill.dev/openapi.html. Thoughts?
2 Replies
rubenf
rubenf4w ago
Yes it should work
mvgijssel
mvgijsselOP4w ago
Can confirm the endpoint works! I've created the following script which enables me to run a single job on an ephemeral worker node:
import os
import wmill
from wmill import task
from wmill import Windmill

client = Windmill()


def execute_on_local_worker():
# List all the files in the local ephemeral worker
files = os.listdir("/opt/setup")
return files


def main(worker_uuid: str):
if not worker_uuid:
raise ValueError(f"worker_uuid is invalid: {worker_uuid}")

# Collect the current custom tags and add the given worker_uuid as a new tag
current_custom_tags = set(client.get("/workers/custom_tags").json())
current_custom_tags.add(worker_uuid)
current_custom_tags = list(current_custom_tags)

# Update the new allowed custom tags in Windmill
result = client.post(
"/settings/global/custom_tags", json={"value": current_custom_tags}
)
print(f"new tags: {current_custom_tags}")

# Hacky way to schedule a job using the given worker_uuid
@task(tag=worker_uuid)
def execute_on_local_worker():
pass

result = execute_on_local_worker()
print(f"from main: {result}")
import os
import wmill
from wmill import task
from wmill import Windmill

client = Windmill()


def execute_on_local_worker():
# List all the files in the local ephemeral worker
files = os.listdir("/opt/setup")
return files


def main(worker_uuid: str):
if not worker_uuid:
raise ValueError(f"worker_uuid is invalid: {worker_uuid}")

# Collect the current custom tags and add the given worker_uuid as a new tag
current_custom_tags = set(client.get("/workers/custom_tags").json())
current_custom_tags.add(worker_uuid)
current_custom_tags = list(current_custom_tags)

# Update the new allowed custom tags in Windmill
result = client.post(
"/settings/global/custom_tags", json={"value": current_custom_tags}
)
print(f"new tags: {current_custom_tags}")

# Hacky way to schedule a job using the given worker_uuid
@task(tag=worker_uuid)
def execute_on_local_worker():
pass

result = execute_on_local_worker()
print(f"from main: {result}")

Did you find this page helpful?