exists worker with tag

Script windmill Verified

by hugo697 ยท 3/6/2024

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 370 days ago
1
/**
2
 * exists worker with tag
3
 *
4
 */
5
export async function main(tag: string | undefined) {
6
  const url = new URL(`${BASE_URL}/api/workers/exists_worker_with_tag`);
7
  for (const [k, v] of [["tag", tag]]) {
8
    if (v !== undefined && v !== "") {
9
      url.searchParams.append(k, v);
10
    }
11
  }
12
  const response = await fetch(url, {
13
    method: "GET",
14
    headers: {
15
      Authorization: "Bearer " + WM_TOKEN,
16
    },
17
    body: undefined,
18
  });
19
  if (!response.ok) {
20
    const text = await response.text();
21
    throw new Error(`${response.status} ${text}`);
22
  }
23
  return await response.json();
24
}
25