The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as cloudtasks from "@distilled.cloud/gcp/cloudtasks_v2"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Layer from "effect/Layer"; |
| 4 | import * as GCPBindings from "../GCPBindings.ts"; |
| 5 | import { grantFor } from "../HttpBinding.ts"; |
| 6 | import { CreateTask, type CreateTaskRequest } from "./CreateTask.ts"; |
| 7 | import type { Queue } from "./Queue.ts"; |
| 8 | |
| 9 | /** |
| 10 | * HTTP implementation of {@link CreateTask}. |
| 11 | * |
| 12 | * @layer |
| 13 | * @provides GCP.CloudTasks.CreateTask |
| 14 | */ |
| 15 | export const CreateTaskHttp = Layer.effect( |
| 16 | CreateTask, |
| 17 | Effect.gen(function* () { |
| 18 | const bind = yield* GCPBindings.Bind; |
| 19 | const createTask = yield* GCPBindings.withCredentials( |
| 20 | cloudtasks.createProjectsLocationsQueuesTasks, |
| 21 | ); |
| 22 | return Effect.fn(function* (queue: Queue) { |
| 23 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 24 | yield* bind`GCP.CloudTasks.CreateTask(${queue})`({ |
| 25 | iam: [ |
| 26 | grantFor({ role: "roles/cloudtasks.enqueuer", on: "cloudtasks.queue" }, queue.name), |
| 27 | ], |
| 28 | }); |
| 29 | } |
| 30 | const name = yield* queue.name; |
| 31 | return Effect.fn(`GCP.CloudTasks.CreateTask(${queue.LogicalId})`)(function* ( |
| 32 | request: CreateTaskRequest, |
| 33 | ) { |
| 34 | return yield* createTask({ |
| 35 | ...request, |
| 36 | parent: yield* name, |
| 37 | }); |
| 38 | }); |
| 39 | }); |
| 40 | }), |
| 41 | ); |