Added method prune again
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2021-01-28 15:57:33 +01:00
parent ca47fe6827
commit 9d5d2e9177
1 changed files with 16 additions and 5 deletions

View File

@ -22,7 +22,20 @@ module.exports = Self => {
const tempPath = path.join(container.client.root, container.name);
const maxAttempts = 3;
prune();
const images = await Self.find({
where: {url: {neq: null}, attempts: {eq: maxAttempts}}
});
for (let image of images) {
const currentStamp = new Date().getTime();
const updatedStamp = image.updated.getTime();
const graceTime = Math.abs(currentStamp - updatedStamp);
const maxTTL = 3600 * 48 * 1000; // 48 hours in ms;
if (graceTime >= maxTTL)
await Self.destroyById(image.itemFk);
}
download();
async function download() {
@ -60,7 +73,6 @@ module.exports = Self => {
});
writeStream.on('close', async function() {
console.log('stream closed');
try {
await models.Image.registerImage('catalog', filePath, fileName, image.itemFk);
await image.destroy();
@ -79,8 +91,7 @@ module.exports = Self => {
try {
const row = await Self.findById(rowId);
if (!row)
throw new Error(`Could not update due error ${error}`);
if (!row) return;
if (row.attempts < maxAttempts) {
await row.updateAttributes({
@ -95,7 +106,7 @@ module.exports = Self => {
download();
} catch (err) {
throw new Error(`ErrorHandler error: ${err}`);
throw new Error(`Image download failed: ${err}`);
}
}
};