The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as batch from "@distilled.cloud/aws/batch"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Layer from "effect/Layer"; |
| 4 | import * as AWSBindings from "../AWSBindings.ts"; |
| 5 | import type { JobDefinition } from "./JobDefinition.ts"; |
| 6 | import type { JobQueue } from "./JobQueue.ts"; |
| 7 | import { SubmitJob, type SubmitJobRequest } from "./SubmitJob.ts"; |
| 8 | |
| 9 | export const SubmitJobHttp = Layer.effect( |
| 10 | SubmitJob, |
| 11 | Effect.gen(function* () { |
| 12 | const bind = yield* AWSBindings.Bind; |
| 13 | const submitJob = yield* AWSBindings.withCredentials(batch.submitJob); |
| 14 | |
| 15 | return Effect.fn(function* (queue: JobQueue, jobDefinition: JobDefinition) { |
| 16 | // Outputs yield a DEFERRED effect — resolve again per invocation below. |
| 17 | const JobQueueArn = yield* queue.jobQueueArn; |
| 18 | const JobDefinitionArn = yield* jobDefinition.jobDefinitionArn; |
| 19 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 20 | yield* bind`AWS.Batch.SubmitJob(${queue}, ${jobDefinition})`({ |
| 21 | policyStatements: [ |
| 22 | { |
| 23 | Effect: "Allow", |
| 24 | Action: ["batch:SubmitJob"], |
| 25 | Resource: [queue.jobQueueArn, jobDefinition.jobDefinitionArn], |
| 26 | }, |
| 27 | ], |
| 28 | }); |
| 29 | } |
| 30 | return Effect.fn(`AWS.Batch.SubmitJob(${queue.LogicalId}, ${jobDefinition.LogicalId})`)( |
| 31 | function* (request: SubmitJobRequest) { |
| 32 | const jobQueueArn = yield* JobQueueArn; |
| 33 | const jobDefinitionArn = yield* JobDefinitionArn; |
| 34 | return yield* submitJob({ |
| 35 | ...request, |
| 36 | jobQueue: jobQueueArn, |
| 37 | jobDefinition: jobDefinitionArn, |
| 38 | }); |
| 39 | }, |
| 40 | ); |
| 41 | }); |
| 42 | }), |
| 43 | ); |