-
-
Save anonymous/1194fc71768f2e453e4064c4a5df43e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Changes b/Changes | |
index bcbab40..f279252 100644 | |
--- a/Changes | |
+++ b/Changes | |
@@ -1,5 +1,7 @@ | |
5.08 2016-05-19 | |
+ - Improved repair methods not to remove finished jobs that still have | |
+ unresolved dependencies. | |
5.07 2016-05-17 | |
- Added support for job dependencies. (jberger, sri) | |
diff --git a/lib/Minion/Backend/Pg.pm b/lib/Minion/Backend/Pg.pm | |
index e52e59c..a031905 100644 | |
--- a/lib/Minion/Backend/Pg.pm | |
+++ b/lib/Minion/Backend/Pg.pm | |
@@ -133,11 +133,13 @@ sub repair { | |
) and state = 'inactive'" | |
); | |
- # Old jobs | |
+ # Old jobs without dependencies | |
$db->query( | |
- "delete from minion_jobs | |
- where state = 'finished' and finished < now() - interval '1 second' * ?", | |
- $minion->remove_after | |
+ "delete from minion_jobs as j | |
+ where finished < now() - interval '1 second' * ? and not exists ( | |
+ select 1 from minion_jobs | |
+ where j.id = any(parents) and state <> 'finished' | |
+ ) and state = 'finished'", $minion->remove_after | |
); | |
} | |
diff --git a/t/pg.t b/t/pg.t | |
index 569f644..5e42e45 100644 | |
--- a/t/pg.t | |
+++ b/t/pg.t | |
@@ -597,10 +597,12 @@ is $minion->job($id4)->info->{result}, 'Non-zero exit status (1)', | |
$worker->unregister; | |
# Job dependencies | |
-$worker = $minion->worker->register; | |
-$id = $minion->enqueue('test'); | |
-$id2 = $minion->enqueue('test'); | |
-$id3 = $minion->enqueue(test => [] => {parents => [$id, $id2]}); | |
+$worker = $minion->remove_after(0)->worker->register; | |
+$minion->repair; | |
+is $minion->stats->{finished_jobs}, 0, 'no finished jobs'; | |
+$id = $minion->enqueue('test'); | |
+$id2 = $minion->enqueue('test'); | |
+$id3 = $minion->enqueue(test => [] => {parents => [$id, $id2]}); | |
is $minion->stats->{delayed_jobs}, 1, 'one delayed job'; | |
$job = $worker->dequeue(0); | |
is $job->id, $id, 'right id'; | |
@@ -623,6 +625,13 @@ $job = $worker->dequeue(0); | |
is $job->id, $id3, 'right id'; | |
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'; | |
+$minion->repair; | |
+is $minion->stats->{finished_jobs}, 2, 'two finished jobs'; | |
+ok $job->finish, 'job finished'; | |
+is $minion->stats->{finished_jobs}, 3, 'three finished jobs'; | |
+$minion->repair; | |
+is $minion->stats->{finished_jobs}, 0, 'no finished jobs'; | |
$id = $minion->enqueue(test => [] => {parents => [-1]}); | |
ok !$worker->dequeue(0), 'job with missing parent will never be ready'; | |
$minion->repair; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment