Fix scanner task creator
This commit is contained in:
+5
-17
@@ -196,30 +196,18 @@ sub CreateReviewTasks {
|
||||
# This avoids MariaDB's inconsistent JSON functions in SQL WHERE clauses,
|
||||
# which behave differently between CLI client and DBI connections.
|
||||
my $sth = $dbh->prepare("
|
||||
SELECT id, video_id, results
|
||||
SELECT id, video_id
|
||||
FROM tasks
|
||||
WHERE task_type='AISCAN' AND status='COMPLETED'
|
||||
WHERE task_type='AISCAN'
|
||||
AND status='COMPLETED'
|
||||
AND JSON_EXTRACT(results, '\$.verdict') = 1
|
||||
AND (SELECT 1 FROM tasks t2 WHERE t2.video_id = tasks.video_id AND t2.task_type = 'REVIEW' LIMIT 1) IS NULL
|
||||
");
|
||||
|
||||
$sth->execute();
|
||||
while (my $row = $sth->fetchrow_hashref()) {
|
||||
my $results = decode_json($row->{results});
|
||||
next unless $results && ref($results) eq 'HASH';
|
||||
next unless $results->{verdict} == 1;
|
||||
next if exists $results->{reviewed};
|
||||
|
||||
print "Creating REVIEW task for video_id: $row->{video_id}\n";
|
||||
create_task($row->{video_id}, 'REVIEW');
|
||||
|
||||
# Re-encode the whole JSON blob in Perl and update it.
|
||||
# This avoids MariaDB JSON_SET path parsing issues through DBI connections.
|
||||
$results->{reviewed} = 1;
|
||||
my $updated = encode_json($results);
|
||||
my $sth_update = $dbh->prepare(
|
||||
"UPDATE tasks SET results = ? WHERE id = ?"
|
||||
);
|
||||
$sth_update->execute($updated, $row->{id});
|
||||
$sth_update->finish();
|
||||
}
|
||||
$sth->finish();
|
||||
}
|
||||
Reference in New Issue
Block a user