]> git.proxmox.com Git - pve-manager.git/blobdiff - PVE/API2/Replication.pm
replication: sent always mail for first three tries and move helper
[pve-manager.git] / PVE / API2 / Replication.pm
index a7e5449749de196284c819836c27f5c618171995..645eab7dc787f149f81808ab3c4c2ea9f8913e8a 100644 (file)
@@ -70,22 +70,23 @@ sub run_single_job {
     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();
 
@@ -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 $@;
            }