-my $update_job_state = sub {
- my ($stateobj, $jobcfg, $state) = @_;
-
- my $plugin = PVE::ReplicationConfig->lookup($jobcfg->{type});
-
- my $vmid = $jobcfg->{guest};
- my $tid = $plugin->get_unique_target_id($jobcfg);
-
- # Note: tuple ($vmid, $tid) is unique
- $stateobj->{$vmid}->{$tid} = $state;
-
- PVE::Tools::file_set_contents($state_path, encode_json($stateobj));
-};
-
-my $get_job_state = sub {
- my ($stateobj, $jobcfg) = @_;
-
- my $plugin = PVE::ReplicationConfig->lookup($jobcfg->{type});
-
- my $vmid = $jobcfg->{guest};
- my $tid = $plugin->get_unique_target_id($jobcfg);
- my $state = $stateobj->{$vmid}->{$tid};
-
- $state = {} if !$state;
-
- $state->{last_iteration} //= 0;
- $state->{last_try} //= 0; # last sync start time
- $state->{last_sync} //= 0; # last successful sync start time
- $state->{fail_count} //= 0;
-
- return $state;
-};
-
-my $read_state = sub {
-
- return {} if ! -e $state_path;
-
- my $raw = PVE::Tools::file_get_contents($state_path);
-
- return {} if $raw eq '';
-
- # untaint $raw
- $raw =~ m/^({.*})$/;
-
- return decode_json($1);
-};
-