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);
};
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) => {
try {
if(err) {
@ -306,8 +329,12 @@ const processImage = (frameBuffer, d, tx, frameLocation, callback) => {
onImageProcessed(d, tx, err, res, body, frameBuffer);
fs.unlinkSync(frameLocation);
removeJob(d.ke, d.id);
});
} catch(ex) {
removeJob(d.ke, d.id);
logError(`Failed to process image, Error: ${ex}`);
if(fs.existsSync(frameLocation)) {
@ -323,6 +350,12 @@ const detectObject = (frameBuffer, d, tx, frameLocation, callback) => {
return;
}
const jobCreated = addJob(d.ke, d.id);
if(!jobCreated) {
return;
}
const dirCreationOptions = {
recursive: true
};
@ -337,6 +370,8 @@ const detectObject = (frameBuffer, d, tx, frameLocation, callback) => {
fs.writeFile(path, frameBuffer, function(err) {
if(err) {
removeJob(d.ke, d.id);
return s.systemLog(err);
}
@ -344,6 +379,8 @@ const detectObject = (frameBuffer, d, tx, frameLocation, callback) => {
processImage(frameBuffer, d, tx, path, callback);
} catch(ex) {
removeJob(d.ke, d.id);
logError(`Detector failed to parse frame, Error: ${ex}`);
}
});