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