From 3df62205dd09ce6a22dba9c1f0948b39e9d3a007 Mon Sep 17 00:00:00 2001 From: conico974 Date: Fri, 14 Mar 2025 10:09:01 +0100 Subject: [PATCH 1/5] [cloudflare] add docs for the durable objects Queue --- pages/cloudflare/caching.mdx | 47 +++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/pages/cloudflare/caching.mdx b/pages/cloudflare/caching.mdx index 8814995..e3903a6 100644 --- a/pages/cloudflare/caching.mdx +++ b/pages/cloudflare/caching.mdx @@ -53,28 +53,57 @@ The binding name used in your app's worker is `NEXT_CACHE_WORKERS_KV`. The servi In your project's OpenNext config, enable the KV cache and set up a queue. -The memory queue will send revalidation requests to a page when needed, and offers support for de-duplicating requests on a per-isolate basis. There might still be duplicate requests under high traffic or across regions. - - - The memory queue provided by `@opennextjs/cloudflare` is not fully suitable for production deployments, you - can use it at your own risk! - +The Durable Object Queue will send revalidation requests to a page when needed, and offers support for de-duplicating requests. +By default there will be a maximum of 10 instance of the Durables Object Queue and they can each process up to 5 requests in parallel.(For up to 50 ISR revalidations in parallel) ```ts // open-next.config.ts import { defineCloudflareConfig } from "@opennextjs/cloudflare"; import kvIncrementalCache from "@opennextjs/cloudflare/kv-cache"; -import memoryQueue from "@opennextjs/cloudflare/memory-queue"; +import doQueue from "@opennextjs/cloudflare/durable-queue"; export default defineCloudflareConfig({ incrementalCache: kvIncrementalCache, - queue: memoryQueue, + queue: doQueue, }); ``` +You will also need to add some binding to your `wrangler.jsonc` file. + +```jsonc +"durable_objects": { + "bindings": [ + { + "name": "NEXT_CACHE_REVALIDATION_DURABLE_OBJECT", + "class_name": "DurableObjectQueueHandler" + } + ] + }, + "migrations": [ + { + "tag": "v1", + "new_sqlite_classes": ["DurableObjectQueueHandler"] + } + ], +``` + +You can customize the behaviors of the queue with environment variables: +- The max number of durable workers that can be created (MAX_REVALIDATE_CONCURRENCY) +- The max number of revalidations that can be processed by an instance of durable worker at the same time (MAX_REVALIDATION_BY_DURABLE_OBJECT) +- The max time in milliseconds that a revalidation can take before being considered as failed (REVALIDATION_TIMEOUT_MS) +- The amount of time after which a revalidation will be attempted again if it failed. If it fails again it will exponentially back off until it reaches the max retry interval (REVALIDATION_RETRY_INTERVAL_MS) +- The maximum number of attempts that can be made to revalidate a path (MAX_REVALIDATION_ATTEMPTS) + + - The `direct` mode for the queue is intended for debugging purposes and is not recommended for use in + There is 2 additional modes that you can use for the queue `direct` and the memory queue + +- The memory queue will dedupe request but only on a per isolate basis. It is not fully suitable for production deployments, you + can use it at your own risk! + +- The `direct` mode for the queue is intended for debugging purposes and is not recommended for use in production. We are actively working on a solution that will be suitable for production. + #### On-Demand Revalidation From df710467c6194c70584e7a32a40e738934a98b39 Mon Sep 17 00:00:00 2001 From: conico974 Date: Fri, 14 Mar 2025 10:18:04 +0100 Subject: [PATCH 2/5] fix linting --- pages/cloudflare/caching.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/cloudflare/caching.mdx b/pages/cloudflare/caching.mdx index e3903a6..6018a45 100644 --- a/pages/cloudflare/caching.mdx +++ b/pages/cloudflare/caching.mdx @@ -88,13 +88,13 @@ You will also need to add some binding to your `wrangler.jsonc` file. ``` You can customize the behaviors of the queue with environment variables: + - The max number of durable workers that can be created (MAX_REVALIDATE_CONCURRENCY) - The max number of revalidations that can be processed by an instance of durable worker at the same time (MAX_REVALIDATION_BY_DURABLE_OBJECT) - The max time in milliseconds that a revalidation can take before being considered as failed (REVALIDATION_TIMEOUT_MS) - The amount of time after which a revalidation will be attempted again if it failed. If it fails again it will exponentially back off until it reaches the max retry interval (REVALIDATION_RETRY_INTERVAL_MS) - The maximum number of attempts that can be made to revalidate a path (MAX_REVALIDATION_ATTEMPTS) - There is 2 additional modes that you can use for the queue `direct` and the memory queue From 42a2d0e6ee0363f07f7ecabdf8a2ddda59d2d1e7 Mon Sep 17 00:00:00 2001 From: conico974 Date: Wed, 19 Mar 2025 11:26:13 +0100 Subject: [PATCH 3/5] update for direct --- pages/cloudflare/caching.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/cloudflare/caching.mdx b/pages/cloudflare/caching.mdx index 6018a45..b7c4cf5 100644 --- a/pages/cloudflare/caching.mdx +++ b/pages/cloudflare/caching.mdx @@ -102,7 +102,7 @@ You can customize the behaviors of the queue with environment variables: can use it at your own risk! - The `direct` mode for the queue is intended for debugging purposes and is not recommended for use in - production. We are actively working on a solution that will be suitable for production. + production. It only works in preview mode (i.e. `wrangler dev`) From edc9ace9bee8683131ebd724488fcf4d11e8d1ab Mon Sep 17 00:00:00 2001 From: conico974 Date: Wed, 19 Mar 2025 11:45:36 +0100 Subject: [PATCH 4/5] Update pages/cloudflare/caching.mdx Co-authored-by: Victor Berchet --- pages/cloudflare/caching.mdx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pages/cloudflare/caching.mdx b/pages/cloudflare/caching.mdx index b7c4cf5..65aa5a4 100644 --- a/pages/cloudflare/caching.mdx +++ b/pages/cloudflare/caching.mdx @@ -89,11 +89,11 @@ You will also need to add some binding to your `wrangler.jsonc` file. You can customize the behaviors of the queue with environment variables: -- The max number of durable workers that can be created (MAX_REVALIDATE_CONCURRENCY) -- The max number of revalidations that can be processed by an instance of durable worker at the same time (MAX_REVALIDATION_BY_DURABLE_OBJECT) -- The max time in milliseconds that a revalidation can take before being considered as failed (REVALIDATION_TIMEOUT_MS) -- The amount of time after which a revalidation will be attempted again if it failed. If it fails again it will exponentially back off until it reaches the max retry interval (REVALIDATION_RETRY_INTERVAL_MS) -- The maximum number of attempts that can be made to revalidate a path (MAX_REVALIDATION_ATTEMPTS) +- The max number of durable workers that can be created (`MAX_REVALIDATE_CONCURRENCY`) +- The max number of revalidations that can be processed by an instance of durable object at the same time (`MAX_REVALIDATION_BY_DURABLE_OBJECT`) +- The max time in milliseconds that a revalidation can take before being considered as failed (`REVALIDATION_TIMEOUT_MS`) +- The amount of time after which a revalidation will be attempted again if it failed. If it fails again it will exponentially back off until it reaches the max retry interval (`REVALIDATION_RETRY_INTERVAL_MS`) +- The maximum number of attempts that can be made to revalidate a path (`MAX_REVALIDATION_ATTEMPTS`) There is 2 additional modes that you can use for the queue `direct` and the memory queue From 187ebb67a21d57e61171b00349cf1239507a1ef5 Mon Sep 17 00:00:00 2001 From: conico974 Date: Fri, 21 Mar 2025 17:58:53 +0100 Subject: [PATCH 5/5] update for #485 --- pages/cloudflare/caching.mdx | 1 + 1 file changed, 1 insertion(+) diff --git a/pages/cloudflare/caching.mdx b/pages/cloudflare/caching.mdx index 65aa5a4..1596429 100644 --- a/pages/cloudflare/caching.mdx +++ b/pages/cloudflare/caching.mdx @@ -94,6 +94,7 @@ You can customize the behaviors of the queue with environment variables: - The max time in milliseconds that a revalidation can take before being considered as failed (`REVALIDATION_TIMEOUT_MS`) - The amount of time after which a revalidation will be attempted again if it failed. If it fails again it will exponentially back off until it reaches the max retry interval (`REVALIDATION_RETRY_INTERVAL_MS`) - The maximum number of attempts that can be made to revalidate a path (`MAX_REVALIDATION_ATTEMPTS`) +- Disable SQLite for this durable object. It should only be used if your incremental cache is not eventually consistent (`REVALIDATION_DO_DISABLE_SQLITE`) There is 2 additional modes that you can use for the queue `direct` and the memory queue