Skip to content

Commit

Permalink
Merge pull request #130 from HEM42/restore_previous_repair_functionality
Browse files Browse the repository at this point in the history
Reimplementation of previous repair, but without significant performance hit
  • Loading branch information
kraih authored Sep 21, 2024
2 parents 00d25ae + 0ab04c2 commit 8de8e3c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions lib/Minion/Backend/Pg.pm
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,14 @@ sub repair {
my $minion = $self->minion;
$db->query("DELETE FROM minion_workers WHERE notified < NOW() - INTERVAL '1 second' * ?", $minion->missing_after);

# Old jobs
$db->query("DELETE FROM minion_jobs WHERE state = 'finished' AND finished <= NOW() - INTERVAL '1 second' * ?",
$minion->remove_after);
# Old jobs with no unresolved dependencies
$db->query(
"DELETE FROM minion_jobs
WHERE id IN (
SELECT id FROM minion_jobs WHERE state = 'finished' AND finished <= NOW() - INTERVAL '1 second' * ?
EXCEPT SELECT unnest(parents) AS id FROM minion_jobs WHERE state != 'finished'
)", $minion->remove_after
);

# Expired jobs
$db->query("DELETE FROM minion_jobs WHERE state = 'inactive' AND expires <= NOW()");
Expand Down
4 changes: 2 additions & 2 deletions t/pg.t
Original file line number Diff line number Diff line change
Expand Up @@ -1116,9 +1116,9 @@ subtest 'Job dependencies' => sub {
is_deeply $job->info->{children}, [], 'right children';
is_deeply $job->info->{parents}, [$id, $id2], 'right parents';
is $minion->stats->{finished_jobs}, 2, 'two finished jobs';
is $minion->repair->stats->{finished_jobs}, 0, 'no finished jobs';
is $minion->repair->stats->{finished_jobs}, 2, 'still two finished jobs';
ok $job->finish, 'job finished';
is $minion->stats->{finished_jobs}, 1, 'one finished job';
is $minion->stats->{finished_jobs}, 3, 'three finished job';
is $minion->repair->remove_after(172800)->stats->{finished_jobs}, 0, 'no finished jobs';
$id = $minion->enqueue(test => [] => {parents => [-1]});
ok $job = $worker->dequeue(0), 'job dequeued';
Expand Down

0 comments on commit 8de8e3c

Please sign in to comment.