Merge branch 'master' of https://gitea.verdnatura.es/verdnatura/salix into test
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2020-08-26 08:28:41 +02:00
commit e12612b0ea
1 changed files with 15 additions and 6 deletions

View File

@ -19,6 +19,7 @@ module.exports = Self => {
Self.downloadImages = async() => { Self.downloadImages = async() => {
const models = Self.app.models; const models = Self.app.models;
let image;
try { try {
const tempPath = path.join('/tmp/salix-image'); const tempPath = path.join('/tmp/salix-image');
@ -26,7 +27,7 @@ module.exports = Self => {
await fs.mkdir(tempPath, {recursive: true}); await fs.mkdir(tempPath, {recursive: true});
const timer = setInterval(async() => { const timer = setInterval(async() => {
const image = await Self.findOne({where: {error: null}}); image = await Self.findOne({where: {error: null}});
// Exit loop // Exit loop
if (!image) return clearInterval(timer); if (!image) return clearInterval(timer);
@ -61,17 +62,25 @@ module.exports = Self => {
await errorHandler(image.itemFk, error, filePath); await errorHandler(image.itemFk, error, filePath);
} }
}); });
}, 1000); }, 1500);
} catch (error) { } catch (error) {
await errorHandler(image.itemFk, error); await errorHandler(image.itemFk, error);
} }
async function errorHandler(rowId, error, filePath) { async function errorHandler(rowId, error, filePath) {
const row = await Self.findById(rowId); try {
await row.updateAttribute('error', error); const row = await Self.findById(rowId);
if (filePath) if (!row)
await fs.unlink(filePath); throw new Error(`Could not update due error ${error}`);
await row.updateAttribute('error', error);
if (filePath)
await fs.unlink(filePath);
} catch (error) {
throw error;
}
} }
}; };
}; };