send http 202 accepted if import is taking a long time
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 34s Details

This commit is contained in:
Ladd Hoffman 2024-04-30 16:57:34 -05:00
parent 40c1fd43d7
commit fb3f842355
2 changed files with 13 additions and 2 deletions

View File

@ -201,11 +201,20 @@ module.exports = async (req, res) => {
console.log(`importFromSS: author ${authorId}`);
const papers = await fetchAuthorPapers(authorId);
console.log('papers count:', papers.length);
const earlyResponseTimeout = setTimeout(() => {
res.status(202).end();
});
const result = await Promise.mapSeries(papers, importPaper);
clearTimeout(earlyResponseTimeout);
if (result.length) {
console.log(`Added posts for ${result.length} papers by author ${authorId}`);
}
res.json(result);
if (!res.headersSent) {
res.json(result);
}
} else {
res.status(400).end();
}

View File

@ -39,7 +39,9 @@ app.use((err, req, res, next) => {
const status = err.response?.status ?? err.status ?? 500;
const message = err.response?.data?.error ?? err.message;
console.error(`error: ${message}`, err);
res.status(status).send(message);
if (!res.headersSent) {
res.status(status).send(message);
}
next();
});