Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry #239

Closed
wants to merge 5 commits into from
Closed

Retry #239

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,26 @@ app.get('/info', async (req, res) => {
res.status(200).send({ currentVersion, latestVersion });
});

const retryHandleEvents = async (events, retries = 5) => {
for (let i = 0; i < retries; i++) {
try {
await handleEvents(events);
return;
} catch (err) {
if (err.response?.status === 504) {
console.error(`Attempt ${i + 1} failed with a 504 error. Retrying...`);
} else {
throw err;
}
}
}
throw new Error('All retry attempts failed with a 504 error.');
};

app.post(config.APP_WEBHOOK_PATH, validateLineSignature, async (req, res) => {
try {
await storage.initialize();
await handleEvents(req.body.events);
await retryHandleEvents(req.body.events);
res.sendStatus(200);
} catch (err) {
console.error(err.message);
Expand Down