1- import logger from "@opennextjs/aws/logger.js " ;
1+ import { debug , error } from "@opennextjs/aws/adapters/ logger" ;
22import type { Queue , QueueMessage } from "@opennextjs/aws/types/overrides.js" ;
33import { IgnorableError } from "@opennextjs/aws/utils/error.js" ;
44
@@ -16,7 +16,7 @@ export const DEFAULT_REVALIDATION_TIMEOUT_MS = 10_000;
1616export class MemoryQueue implements Queue {
1717 readonly name = "memory-queue" ;
1818
19- revalidatedPaths = new Map < string , ReturnType < typeof setTimeout > > ( ) ;
19+ revalidatedPaths = new Set < string > ( ) ;
2020
2121 constructor ( private opts = { revalidationTimeoutMs : DEFAULT_REVALIDATION_TIMEOUT_MS } ) { }
2222
@@ -26,10 +26,8 @@ export class MemoryQueue implements Queue {
2626
2727 if ( this . revalidatedPaths . has ( MessageDeduplicationId ) ) return ;
2828
29- this . revalidatedPaths . set (
29+ this . revalidatedPaths . add (
3030 MessageDeduplicationId ,
31- // force remove to allow new revalidations incase something went wrong
32- setTimeout ( ( ) => this . revalidatedPaths . delete ( MessageDeduplicationId ) , this . opts . revalidationTimeoutMs )
3331 ) ;
3432
3533 try {
@@ -38,17 +36,24 @@ export class MemoryQueue implements Queue {
3836 // TODO: Drop the import - https://github.com/opennextjs/opennextjs-cloudflare/issues/361
3937 // @ts -ignore
4038 const manifest = await import ( "./.next/prerender-manifest.json" ) ;
41- await service . fetch ( `${ protocol } ://${ host } ${ url } ` , {
39+ const response = await service . fetch ( `${ protocol } ://${ host } ${ url } ` , {
4240 method : "HEAD" ,
4341 headers : {
4442 "x-prerender-revalidate" : manifest . preview . previewModeId ,
4543 "x-isr" : "1" ,
4644 } ,
45+ // We want to timeout the revalidation to avoid hanging the queue
46+ signal : AbortSignal . timeout ( this . opts . revalidationTimeoutMs ) ,
4747 } ) ;
48+
49+ // Here we want at least to log when the revalidation was not successful
50+ if ( response . status !== 200 || response . headers . get ( "x-nextjs-cache" ) !== "REVALIDATED" ) {
51+ error ( `Revalidation failed for ${ url } with status ${ response . status } ` ) ;
52+ }
53+ debug ( `Revalidation successful for ${ url } ` ) ;
4854 } catch ( e ) {
49- logger . error ( e ) ;
55+ error ( e ) ;
5056 } finally {
51- clearTimeout ( this . revalidatedPaths . get ( MessageDeduplicationId ) ) ;
5257 this . revalidatedPaths . delete ( MessageDeduplicationId ) ;
5358 }
5459 }
0 commit comments