]> git.proxmox.com Git - pve-zsync.git/commitdiff
Detect other running instances of the same job
authorFabian Ebner <f.ebner@proxmox.com>
Thu, 10 Oct 2019 09:55:16 +0000 (11:55 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 11 Oct 2019 09:51:16 +0000 (11:51 +0200)
A 'waiting' state is introduced and other 'waiting' and 'syncing'
instances of the same job are now detected by moving the check out
from the sync lock.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
pve-zsync

index cfd8c0849b2cbb9463f15b450d9183eb32ad2f79..abaa225b4cdd20c6064f04f56b36a3acd2b971b1 100755 (executable)
--- a/pve-zsync
+++ b/pve-zsync
@@ -585,22 +585,33 @@ sub destroy_job {
 sub sync {
     my ($param) = @_;
 
+    my $job;
+
+    locked("$CONFIG_PATH/cron_and_state.lock", sub {
+       eval { $job = get_job($param) };
+
+       if ($job) {
+           if (defined($job->{state}) && ($job->{state} eq "syncing" || $job->{state} eq "waiting")) {
+               die "Job --source $param->{source} --name $param->{name} is already scheduled to sync\n";
+           }
+
+           $job->{state} = "waiting";
+           update_state($job);
+       }
+    });
+
     locked("$CONFIG_PATH/sync.lock", sub {
 
        my $date = get_date();
-       my $job;
 
        my $dest;
        my $source;
        my $vm_type;
 
        locked("$CONFIG_PATH/cron_and_state.lock", sub {
+           #job might've changed while we waited for the sync lock, but we can be sure it's not syncing
            eval { $job = get_job($param); };
 
-           if ($job && defined($job->{state}) && $job->{state} eq "syncing") {
-               die "Job --source $param->{source} --name $param->{name} is syncing at the moment";
-           }
-
            $dest = parse_target($param->{dest});
            $source = parse_target($param->{source});