You could probably use an alarm on the attached durable object and keep waking it
You could probably use an alarm on the attached durable object and keep waking it

getRandom(env.API, 25) to a more reasonable valueinternal error; reference = 0sp6nv1fqj06ub0q9b0qbfjq


~~wrangler containers images list~~ I just realized this is the WRONG command, that is for 'images' , not 'instances' - I want to delete instances, not images.js import { Container, getRandom } from "@cloudflare/containers";
interface Env {
API: any; // Container binding
API_KEY: string;
CLEANUP_TEMP_FILES: string;
LOG_LEVEL: string;
PORT: string;
R2_ACCESS_KEY_ID: string;
R2_BUCKET_NAME: string;
R2_ENDPOINT_URL: string;
R2_PUBLIC_URL: string;
R2_SECRET_ACCESS_KEY: string;
}
export class PowerpointApi extends Container {
declare env: Env;
defaultPort = 8000;
sleepAfter = "2m";
envVars: Record<string, string> = {
API_KEY: this.env.API_KEY,
CLEANUP_TEMP_FILES: this.env.CLEANUP_TEMP_FILES,
LOG_LEVEL: this.env.LOG_LEVEL,
PORT: this.env.PORT,
R2_ACCESS_KEY_ID: this.env.R2_ACCESS_KEY_ID,
R2_BUCKET_NAME: this.env.R2_BUCKET_NAME,
R2_ENDPOINT_URL: this.env.R2_ENDPOINT_URL,
R2_PUBLIC_URL: this.env.R2_PUBLIC_URL,
R2_SECRET_ACCESS_KEY: this.env.R2_SECRET_ACCESS_KEY,
};
override onStart() {
console.log("Container successfully started");
}
override onStop() {
console.log("Container successfully shut down");
}
override onError(error: unknown) {
console.log("Container error:", error);
}
}
export default {
async fetch(request: Request, env: Env): Promise<Response> {
const container = await getRandom(env.API, 25);
return await container.fetch(request);
},
} satisfies ExportedHandler<Env>; const container = getContainer(env.MY_CONTAINER);
const containerState = await container.getState();
if (containerState.status === "stopped") {
await container.startAndWaitForPorts({
startOptions: {
envVars: {
OPENSTATUS_KEY: env.OPENSTATUS_KEY,
},
},
});
} else {
await container.renewActivityTimeout();
}~~wrangler containers images list~~