From a68b66204fdd989e49301375810af9a34ca51892 Mon Sep 17 00:00:00 2001 From: Akira Sawada Date: Sat, 13 Mar 2021 15:30:24 +0900 Subject: [PATCH] Ignore exceptions while saving exitstatus Since it could break normal job closing and bring duplicated executions. --- lib/TheSchwartz/Job.pm | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/TheSchwartz/Job.pm b/lib/TheSchwartz/Job.pm index dedb181..f1b3bf1 100644 --- a/lib/TheSchwartz/Job.pm +++ b/lib/TheSchwartz/Job.pm @@ -183,7 +183,27 @@ sub set_exit_status { } my $driver = $job->driver; - $driver->insert($status); + eval { + $driver->insert($status); + }; + if ( my $e = $@ ) { + my $jobid = $job->jobid; + if ( $e =~ /Failed to execute INSERT INTO exitstatus/ + && $e =~ /Duplicate entry/ ) { + # Already saved exitstatus, it means this job was + # already executed. + # Ignore this... + print STDERR "Got duplicated entry for exitstatus($exit) of job $jobid: $e\n"; + print STDERR Dumper $job; + } + else { + print STDERR "Got an error when saving exitstatus($exit) of job $jobid: $e\n"; + print STDERR Dumper $job; + } + + # Anyway, we can't do anything here. Just ignore the exception. + } + # and let's lazily clean some exitstatus while we're here. but # rather than doing this query all the time, we do it 1/nth of the