fix(worker): fix segment processing/file upload status

pull/4/head
Cameron Clough 2022-03-24 22:52:21 +00:00
parent 07551a7514
commit c59f2a07ea
No known key found for this signature in database
GPG Key ID: BFB3B74B026ED43F
1 changed files with 35 additions and 36 deletions

View File

@ -210,7 +210,7 @@ async function processSegmentsRecursive() {
logger.error(`FAILING TO PROCESS SEGMENT,${dongleId} ${driveIdentifier} ${segmentId} JSON: ${JSON.stringify(segment)} SKIPPING `);
segmentProcessPosition += 1;
} else {
Promise.all([
await Promise.all([
processSegmentRLog(fileStatus['rlog.bz2']),
processSegmentVideo(fileStatus['qcamera.ts']),
])
@ -269,13 +269,12 @@ async function updateSegments() {
});
logger.info('updateSegments - total segments', segments.length);
if (segments.length > 0) {
// we process at most 15 segments per batch
segments.length = Math.min(segments.length, 15);
logger.debug(`updateSegments - processing ${segments.length} segments`);
await Promise.all(segments.map(async (segment) => {
logger.debug('updateSegments - segment', segment);
// we process at most 15 segments per batch
if (segmentProcessQueue.length >= 15) {
return;
}
const {
id,
created,
@ -284,6 +283,7 @@ async function updateSegments() {
is_processed: isProcessed,
segment_id: segmentId,
} = segment;
logger.debug('updateSegments - segment', driveIdentifier, segmentId);
const dongleIdHash = crypto.createHmac('sha256', process.env.APP_SALT)
.update(dongleId)
@ -309,21 +309,21 @@ async function updateSegments() {
rlog: 'rlog.bz2',
};
const fileStatus = {
[SegmentFiles.fcamera]: false,
[SegmentFiles.dcamera]: false,
[SegmentFiles.qcamera]: false,
[SegmentFiles.qlog]: false,
[SegmentFiles.rlog]: false,
[SegmentFiles.fcamera]: undefined,
[SegmentFiles.dcamera]: undefined,
[SegmentFiles.qcamera]: undefined,
[SegmentFiles.qlog]: undefined,
[SegmentFiles.rlog]: undefined,
};
directoryTree.children.forEach((file) => {
if (file.name in fileStatus) {
logger.debug('updateSegments - found file', file.name);
fileStatus[file.name] = true;
fileStatus[file.name] = file.path;
}
});
const uploadComplete = Object.keys(fileStatus).every((key) => fileStatus[key]);
const uploadComplete = Object.keys(fileStatus).every((key) => !!fileStatus[key]);
logger.debug('updateSegments - uploadComplete', uploadComplete);
if (fileStatus[SegmentFiles.qcamera] && fileStatus[SegmentFiles.rlog] && !isProcessed) {
@ -353,7 +353,6 @@ async function updateSegments() {
}, { where: { id } });
}
}));
}
if (segmentProcessQueue.length > 0) {
logger.info('updateSegments - processing', segmentProcessQueue.length);