]> git.proxmox.com Git - pve-guest-common.git/blobdiff - PVE/ReplicationState.pm
replication: improve schedule_job_now
[pve-guest-common.git] / PVE / ReplicationState.pm
index b817f08cc8b2aedf4d559bdf402e668d2864c6e3..1e74809a00999f2d7a6d03070c72dd1eedb1a160 100644 (file)
@@ -299,7 +299,7 @@ sub get_next_job {
        my $jobb = $jobs->{$b};
        my $sa =  $joba->{state};
        my $sb =  $jobb->{state};
-       my $res = $sa->{last_iteration} cmp $sb->{last_iteration};
+       my $res = $sa->{last_iteration} <=> $sb->{last_iteration};
        return $res if $res != 0;
        $res = $joba->{next_sync} <=> $jobb->{next_sync};
        return $res if $res != 0;
@@ -317,4 +317,22 @@ sub get_next_job {
     return undef;
 }
 
+sub schedule_job_now {
+    my ($jobcfg) = @_;
+    PVE::GuestHelpers::guest_migration_lock($jobcfg->{guest}, undef, sub {
+       PVE::Tools::lock_file($state_lock, 10, sub {
+           my $stateobj = read_state();
+           my $vmid = $jobcfg->{guest};
+           my $tid = $plugin->get_unique_target_id($jobcfg);
+           # no not modify anything if there is no state
+           return if !defined($stateobj->{$vmid}->{$tid});
+
+           my $state = read_job_state($jobcfg);
+           $state->{last_try} = 0;
+           write_job_state($jobcfg, $state);
+       });
+       die $@ if $@;
+    });
+}
+
 1;