Skip to content

非公式 / UnofficialCloudflare, Inc. 非提携。アカウント情報は入力しないでください。Not affiliated with Cloudflare, Inc. Do not enter Cloudflare credentials here.Official docsこのサイトについてプライバシー

カスタムリソース制限

最終更新 Markdown で表示Agent セットアップ

既定では、各 Dynamic Worker の呼び出しは、CPU 時間とサブリクエストについて Workers プランの 上限 を使います。カスタム制限を使うと、Dynamic Worker のリソース使用量に、プログラムからより低い上限を適用できます。

呼び出しごとの最大 CPU 時間とサブリクエスト数の上限を設定できます。Dynamic Worker がいずれかの上限に達すると、すぐに例外を投げます。

カスタム制限を設定する

カスタム制限は、Worker コードの一部として指定できます。

const worker = env.LOADER.get("my-worker", async () => {
  return {
    compatibilityDate: "$today",
    mainModule: "index.js",
    modules: { "index.js": code },
    limits: { cpuMs: 10, subRequests: 5 },
  };
});

getEntrypoint() 呼び出しの一部としても指定できます。

// get the worker's default entrypoint with custom limits
// if limits were already specified as part of the worker code, the lower of the two limits is used
const entrypoint = worker.getEntrypoint(null, { limits: { cpuMs: 10, subRequests: 5 } });
await entrypoint.fetch(...);

役に立ちましたか?