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