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 (?, ?)",
182
+
"INSERT OR REPLACE INTO failed_state (id, data, buildId) VALUES (?, ?, ?)",
174
183
msg.MessageDeduplicationId,
175
-
JSON.stringify(updatedFailedState)
184
+
JSON.stringify(updatedFailedState),
185
+
process.env.__NEXT_BUILD_ID
176
186
);
177
187
// We probably want to do something if routeInFailedState is becoming too big, at least log it
178
188
awaitthis.addAlarm();
@@ -198,10 +208,14 @@ export class DurableObjectQueueHandler extends DurableObject<CloudflareEnv> {
198
208
// We only restore the failed state and the alarm
199
209
asyncinitState(){
200
210
// We store the failed state as a blob, we don't want to do anything with it anyway besides restoring
201
-
this.sql.exec("CREATE TABLE IF NOT EXISTS failed_state (id TEXT PRIMARY KEY, data TEXT)");
211
+
this.sql.exec("CREATE TABLE IF NOT EXISTS failed_state (id TEXT PRIMARY KEY, data TEXT, buildId TEXT)");
202
212
203
213
// We create the sync table to handle eventually consistent incremental cache
204
-
this.sql.exec("CREATE TABLE IF NOT EXISTS sync (id TEXT PRIMARY KEY, lastSuccess INTEGER)");
214
+
this.sql.exec("CREATE TABLE IF NOT EXISTS sync (id TEXT PRIMARY KEY, lastSuccess INTEGER, buildId TEXT)");
215
+
216
+
// Before doing anything else, we clear the DB for any potential old data
217
+
this.sql.exec("DELETE FROM failed_state WHERE buildId != ?",process.env.__NEXT_BUILD_ID);
218
+
this.sql.exec("DELETE FROM sync WHERE buildId != ?",process.env.__NEXT_BUILD_ID);
205
219
206
220
constfailedStateCursor=this.sql.exec<{id: string;data: string}>("SELECT * FROM failed_state");
207
221
for(constrowoffailedStateCursor){
@@ -222,7 +236,11 @@ export class DurableObjectQueueHandler extends DurableObject<CloudflareEnv> {
222
236
constisNewer=this.sql
223
237
.exec<{
224
238
isNewer: number;
225
-
}>("SELECT COUNT(*) as isNewer FROM sync WHERE id = ? AND lastSuccess > ?",`${msg.MessageBody.host}${msg.MessageBody.url}`,Math.round(msg.MessageBody.lastModified/1000))
239
+
}>(
240
+
"SELECT COUNT(*) as isNewer FROM sync WHERE id = ? AND lastSuccess > ?",
0 commit comments