]> git.proxmox.com Git - pmg-api.git/commitdiff
api: pbs schedule: return next-run
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 18 Nov 2020 15:30:44 +0000 (16:30 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 18 Nov 2020 15:30:44 +0000 (16:30 +0100)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/PMG/API2/PBS/Job.pm
src/PMG/PBSSchedule.pm

index 91e0f818a2b206e06d8c0dbe2135e830241374c1..793ad88d1ecd2d9e9c3dc5d331eeeb28c9899c27 100644 (file)
@@ -500,6 +500,11 @@ __PACKAGE__->register_method ({
                type => 'string', pattern => '[0-9a-zA-Z. ]+',
                default => '5min', optional => 1,
            },
+           'next-run' => {
+               description => "The date time of the next run, in server locale.",
+               type => 'string',
+               optional => 1,
+           },
            unitfile => {
                description => "unit file for the systemd.timer unit",
                type => 'string', optional => 1,
index 46d0b18b69487b603d92028464456d9c72f0b3c5..92de542e6d865c75c287ea9836e6926e1848ea33 100644 (file)
@@ -6,7 +6,27 @@ use warnings;
 use PVE::Tools qw(run_command file_set_contents file_get_contents trim dir_glob_foreach);
 use PVE::Systemd;
 
-# systemd timer
+# note: not exactly cheap...
+my sub next_calendar_event {
+    my ($spec) = @_;
+
+    my $res = '-';
+    eval {
+       run_command(
+           ['systemd-analyze', 'calendar', $spec],
+           noerr => 1,
+           outfunc => sub {
+               my $line = shift;
+               if ($line =~ /^\s*Next elapse:\s*(.+)$/) {
+                   $res = $1;
+               }
+           },
+       );
+    };
+    return $res;
+}
+
+# systemd timer, filter optionally by a $remote
 sub get_schedules {
     my ($filter_remote) = @_;
 
@@ -29,12 +49,14 @@ sub get_schedules {
 
        my $unitfile = "$systemd_dir/$filename";
        my $unit = PVE::Systemd::read_ini($unitfile);
+       my $timer = $unit->{'Timer'};
 
        push @$result, {
            unitfile => $unitfile,
            remote => $remote,
-           schedule => $unit->{'Timer'}->{'OnCalendar'},
-           delay => $unit->{'Timer'}->{'RandomizedDelaySec'},
+           schedule => $timer->{'OnCalendar'},
+           delay => $timer->{'RandomizedDelaySec'},
+           'next-run' => next_calendar_event($timer->{'OnCalendar'}),
        };
     });
 
@@ -51,8 +73,16 @@ sub create_schedule {
     my $timer_unit_path = "/etc/systemd/system/$timer_unit";
 
     # create systemd timer
-    run_command(['systemd-analyze', 'calendar', $schedule], errmsg => "Invalid schedule specification", outfunc => sub {});
-    run_command(['systemd-analyze', 'timespan', $delay], errmsg => "Invalid delay specification", outfunc => sub {});
+    run_command(
+       ['systemd-analyze', 'calendar', $schedule],
+       errmsg => "Invalid schedule specification",
+       outfunc => sub {},
+    );
+    run_command(
+       ['systemd-analyze', 'timespan', $delay],
+       errmsg => "Invalid delay specification",
+       outfunc => sub {},
+    );
     my $timer = {
        'Unit' => {
            'Description' => "Timer for PBS Backup to remote $remote",