Added clearInterval()
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2020-08-18 08:37:39 +02:00
parent 8968f41b75
commit 1ef6637ad3
1 changed files with 5 additions and 2 deletions

View File

@ -27,12 +27,15 @@ module.exports = Self => {
// Create temporary path // Create temporary path
await fs.mkdir(tempPath, {recursive: true}); await fs.mkdir(tempPath, {recursive: true});
setInterval(async() => { const timer = setInterval(async() => {
const image = await Self.findOne({where: {error: null}}); const image = await Self.findOne({where: {error: null}});
const fileName = `${image.itemFk}.png`; const fileName = `${image.itemFk}.png`;
const filePath = path.join(tempPath, fileName); const filePath = path.join(tempPath, fileName);
const file = fs.createWriteStream(filePath);
// Exit loop
if (!image) clearInterval(timer);
const file = fs.createWriteStream(filePath);
https.get(image.url, async response => { https.get(image.url, async response => {
if (response.statusCode != 200) { if (response.statusCode != 200) {
const error = new Error(`Could not download the image. Status code ${response.statusCode}`); const error = new Error(`Could not download the image. Status code ${response.statusCode}`);