Skip to content

Commit 410bebe

Browse files
committed
wip: add retry, missing test
1 parent 22e6815 commit 410bebe

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/DefinedSchemas.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export class DefinedSchemas {
88
constructor(localSchemas, config) {
99
this.config = Config.get(config.appId);
1010
this.localSchemas = localSchemas;
11+
this.retries = 0;
12+
this.maxRetries = 3;
1113
}
1214

1315
// Simulate save like the SDK
@@ -58,8 +60,18 @@ export class DefinedSchemas {
5860
await Promise.all(this.localSchemas.map(async localSchema => this.saveOrUpdate(localSchema)));
5961
await this.enforceCLPForNonProvidedClass();
6062
} catch (e) {
61-
logger.error(e);
62-
if (process.env.NODE_ENV === 'production') process.exit(1);
63+
if (this.retries <= this.maxRetries) {
64+
this.retries++;
65+
// first retry 1sec, 2sec, 3sec total 6sec retry sequence
66+
// retry will only happen in case of deploying multi parse server instance
67+
// at the same time
68+
// modern systems like k8 avoid this by doing rolling updates
69+
await new Promise(resolve => setTimeout(resolve, 1000 * this.retries));
70+
await this.execute();
71+
} else {
72+
logger.error(e);
73+
if (process.env.NODE_ENV === 'production') process.exit(1);
74+
}
6375
}
6476
}
6577

0 commit comments

Comments
 (0)