prevent same event source (groupId + monitorId) to run in parallel in the same plugin, aligned DeepStack object detection plugin

face-manager-integrated
Elad Bar 2022-12-11 08:52:51 +02:00
parent 95de2f6348
commit aa2a43e79a
1 changed files with 37 additions and 0 deletions

View File

@ -137,6 +137,29 @@ const initialize = () => {
request.post(startupRequestData, handleStartupResponse); request.post(startupRequestData, handleStartupResponse);
}; };
const getJobKey = (groupId, monitorId) => {
const jobKey = `${groupId}_${monitorId}`;
return jobKey;
}
const addJob = (groupId, monitorId) => {
const jobKey = getJobKey(groupId, monitorId);
const jobExists = detectorSettings.jobs.includes(jobKey);
if(!jobExists) {
detectorSettings.jobs.push(jobKey);
}
return !jobExists;
}
const removeJob = (groupId, monitorId) => {
const jobKey = getJobKey(groupId, monitorId);
detectorSettings.jobs = detectorSettings.jobs.filter(j => j !== jobKey);
}
const handleStartupResponse = (err, res, body) => { const handleStartupResponse = (err, res, body) => {
try { try {
if(err) { if(err) {
@ -306,8 +329,12 @@ const processImage = (frameBuffer, d, tx, frameLocation, callback) => {
onImageProcessed(d, tx, err, res, body, frameBuffer); onImageProcessed(d, tx, err, res, body, frameBuffer);
fs.unlinkSync(frameLocation); fs.unlinkSync(frameLocation);
removeJob(d.ke, d.id);
}); });
} catch(ex) { } catch(ex) {
removeJob(d.ke, d.id);
logError(`Failed to process image, Error: ${ex}`); logError(`Failed to process image, Error: ${ex}`);
if(fs.existsSync(frameLocation)) { if(fs.existsSync(frameLocation)) {
@ -323,6 +350,12 @@ const detectObject = (frameBuffer, d, tx, frameLocation, callback) => {
return; return;
} }
const jobCreated = addJob(d.ke, d.id);
if(!jobCreated) {
return;
}
const dirCreationOptions = { const dirCreationOptions = {
recursive: true recursive: true
}; };
@ -337,6 +370,8 @@ const detectObject = (frameBuffer, d, tx, frameLocation, callback) => {
fs.writeFile(path, frameBuffer, function(err) { fs.writeFile(path, frameBuffer, function(err) {
if(err) { if(err) {
removeJob(d.ke, d.id);
return s.systemLog(err); return s.systemLog(err);
} }
@ -344,6 +379,8 @@ const detectObject = (frameBuffer, d, tx, frameLocation, callback) => {
processImage(frameBuffer, d, tx, path, callback); processImage(frameBuffer, d, tx, path, callback);
} catch(ex) { } catch(ex) {
removeJob(d.ke, d.id);
logError(`Detector failed to parse frame, Error: ${ex}`); logError(`Detector failed to parse frame, Error: ${ex}`);
} }
}); });