Skip to content

Commit

Permalink
fix(api): sleep if image hasn’t changed during retry loop
Browse files Browse the repository at this point in the history
  • Loading branch information
jakowenko committed Jun 12, 2022
1 parent 957c0ed commit 78e9808
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions api/src/util/process.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ module.exports.polling = async (
if (breakMatch === true && MATCH_IDS.includes(id)) break;

const stream = await this.stream(url);
if (stream && previousContentLength !== stream.length) {
const streamChanged = stream && previousContentLength !== stream.length;
if (streamChanged) {
const tmp = {
source: `${STORAGE.TMP.PATH}/${id}-${type}-${uuidv4()}.jpg`,
mask: false,
Expand Down Expand Up @@ -85,7 +86,11 @@ module.exports.polling = async (
if (breakMatch === true) break;
}
}
if (frigateEventType && delay > 0) await sleep(delay);

/* if the image hasn't changed or the user has a delay set, sleep before trying to find another image
to increase the changes it changed */
if ((frigateEventType && delay > 0) || !streamChanged)
await sleep(frigateEventType && delay > 0 ? delay : i * 0.5);
}
}

Expand Down

0 comments on commit 78e9808

Please sign in to comment.