die $@ if $@;
}
-# passing $now and $verbose is useful for regression testing
-sub run_jobs {
- my ($now, $logfunc, $verbose, $mail) = @_;
- my $mail_at_fail_count = sub {
- my ($fail_count) = @_;
+my sub _should_mail_at_failcount {
+ my ($fail_count) = @_;
- return 1 if $fail_count == 1;
+ return 1 if $fail_count <= 3; # always send the first few for better visibility of the issue
- # failing job is re-tried every half hour, try to send one mail after 1, 2, 4, 8, etc. days
- my $i = 1;
- while ($i * 48 < $fail_count) {
- $i = $i * 2;
- }
- return $i * 48 == $fail_count;
- };
+ # failing job is re-tried every half hour, try to send one mail after 1, 2, 4, 8, etc. days
+ my $i = 1;
+ while ($i * 48 < $fail_count) {
+ $i = $i * 2;
+ }
+ return $i * 48 == $fail_count;
+};
+
+# passing $now and $verbose is useful for regression testing
+sub run_jobs {
+ my ($now, $logfunc, $verbose, $mail) = @_;
my $iteration = $now // time();
my $jobstate = PVE::ReplicationState::extract_job_state($state, $jobcfg);
eval {
PVE::Tools::sendmail('root', "Replication Job: $jobcfg->{id} failed", $err)
- if $mail && $mail_at_fail_count->($jobstate->{fail_count});
+ if $mail && _should_mail_at_failcount($jobstate->{fail_count});
};
warn ": $@" if $@;
}