send http 202 accepted if import is taking a long time
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 34s
Details
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 34s
Details
This commit is contained in:
parent
40c1fd43d7
commit
fb3f842355
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue