You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"INSERT OR REPLACE INTO failed_state (id, data) VALUES (?, ?)",
189
+
"INSERT OR REPLACE INTO failed_state (id, data, buildId) VALUES (?, ?, ?)",
188
190
msg.MessageDeduplicationId,
189
-
JSON.stringify(updatedFailedState)
191
+
JSON.stringify(updatedFailedState),
192
+
process.env.__NEXT_BUILD_ID
190
193
);
191
194
// We probably want to do something if routeInFailedState is becoming too big, at least log it
192
195
awaitthis.addAlarm();
@@ -213,10 +216,14 @@ export class DurableObjectQueueHandler extends DurableObject<CloudflareEnv> {
213
216
// We only restore the failed state and the alarm
214
217
asyncinitState(){
215
218
// We store the failed state as a blob, we don't want to do anything with it anyway besides restoring
216
-
this.sql.exec("CREATE TABLE IF NOT EXISTS failed_state (id TEXT PRIMARY KEY, data TEXT)");
219
+
this.sql.exec("CREATE TABLE IF NOT EXISTS failed_state (id TEXT PRIMARY KEY, data TEXT, buildId TEXT)");
217
220
218
221
// We create the sync table to handle eventually consistent incremental cache
219
-
this.sql.exec("CREATE TABLE IF NOT EXISTS sync (id TEXT PRIMARY KEY, lastSuccess INTEGER)");
222
+
this.sql.exec("CREATE TABLE IF NOT EXISTS sync (id TEXT PRIMARY KEY, lastSuccess INTEGER, buildId TEXT)");
223
+
224
+
// Before doing anything else, we clear the DB for any potential old data
225
+
this.sql.exec("DELETE FROM failed_state WHERE buildId != ?",process.env.__NEXT_BUILD_ID);
226
+
this.sql.exec("DELETE FROM sync WHERE buildId != ?",process.env.__NEXT_BUILD_ID);
220
227
221
228
constfailedStateCursor=this.sql.exec<{id: string;data: string}>("SELECT * FROM failed_state");
222
229
for(constrowoffailedStateCursor){
@@ -237,7 +244,11 @@ export class DurableObjectQueueHandler extends DurableObject<CloudflareEnv> {
237
244
constisNewer=this.sql
238
245
.exec<{
239
246
isNewer: number;
240
-
}>("SELECT COUNT(*) as isNewer FROM sync WHERE id = ? AND lastSuccess > ?",`${msg.MessageBody.host}${msg.MessageBody.url}`,Math.round(msg.MessageBody.lastModified/1000))
247
+
}>(
248
+
"SELECT COUNT(*) as isNewer FROM sync WHERE id = ? AND lastSuccess > ?",
0 commit comments