replication: sent always mail for first three tries and move helper

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2022-04-27 09:48:27 +02:00
parent 237f00be03
commit fa4bb659a3

View File

@ -70,23 +70,24 @@ sub run_single_job {
die $@ if $@;
}
my sub _should_mail_at_failcount {
my ($fail_count) = @_;
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;
};
# 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) = @_;
return 1 if $fail_count == 1;
# 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;
};
my $iteration = $now // time();
my $code = sub {
@ -106,7 +107,7 @@ sub run_jobs {
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 $@;
}