public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH manager v3 1/3] fix #4026: add 'repeat-missed' option for jobs
Date: Mon, 13 Jun 2022 15:24:08 +0200	[thread overview]
Message-ID: <20220613132411.3736044-2-d.csapak@proxmox.com> (raw)
In-Reply-To: <20220613132411.3736044-1-d.csapak@proxmox.com>

like systemd-timers 'persistent'. so that the user can configure it to not be
run after powering up when it was previously missed

this reverses the default behaviour to not run missed jobs after pvescheduler
was started, since most of the time that's not the desired behaviour

since we don't use it for updated schedules anymore, rename
'updated_job_schedule' to 'update_last_runtime'

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Reviewed-by: Fabian Ebner <f.ebner@proxmox.com>
---
 PVE/API2/Backup.pm          | 23 +++++++++++++++++++++--
 PVE/Jobs.pm                 |  8 +++++++-
 PVE/Jobs/Plugin.pm          |  7 +++++++
 PVE/Jobs/VZDump.pm          |  1 +
 PVE/Service/pvescheduler.pm |  6 +++++-
 5 files changed, 41 insertions(+), 4 deletions(-)

diff --git a/PVE/API2/Backup.pm b/PVE/API2/Backup.pm
index 5d36789a..9043c71a 100644
--- a/PVE/API2/Backup.pm
+++ b/PVE/API2/Backup.pm
@@ -180,6 +180,13 @@ __PACKAGE__->register_method({
 		description => "Enable or disable the job.",
 		default => '1',
 	    },
+	    'repeat-missed' => {
+		optional => 1,
+		type => 'boolean',
+		description => "If true, the job will be run as soon as possible if it was missed".
+		    " while the scheduler was not running.",
+		default => 0,
+	    },
 	    comment => {
 		optional => 1,
 		type => 'string',
@@ -381,6 +388,13 @@ __PACKAGE__->register_method({
 		description => "Enable or disable the job.",
 		default => '1',
 	    },
+	    'repeat-missed' => {
+		optional => 1,
+		type => 'boolean',
+		description => "If true, the job will be run as soon as possible if it was missed".
+		    " while the scheduler was not running.",
+		default => 0,
+	    },
 	    comment => {
 		optional => 1,
 		type => 'string',
@@ -440,8 +454,13 @@ __PACKAGE__->register_method({
 		die "no such vzdump job\n" if !$job || $job->{type} ne 'vzdump';
 	    }
 
+	    my $deletable = {
+		comment => 1,
+		'repeat-missed' => 1,
+	    };
+
 	    foreach my $k (@$delete) {
-		if (!PVE::VZDump::option_exists($k) && $k ne 'comment') {
+		if (!PVE::VZDump::option_exists($k) && !$deletable->{$k}) {
 		    raise_param_exc({ delete => "unknown option '$k'" });
 		}
 
@@ -475,7 +494,7 @@ __PACKAGE__->register_method({
 	    PVE::VZDump::verify_vzdump_parameters($job, 1);
 
 	    if ($schedule_updated) {
-		PVE::Jobs::updated_job_schedule($id, 'vzdump');
+		PVE::Jobs::update_last_runtime($id, 'vzdump');
 	    }
 
 	    if (defined($idx)) {
diff --git a/PVE/Jobs.pm b/PVE/Jobs.pm
index da648630..1091bc22 100644
--- a/PVE/Jobs.pm
+++ b/PVE/Jobs.pm
@@ -180,7 +180,7 @@ sub started_job {
 }
 
 # will be called when the job schedule is updated
-sub updated_job_schedule {
+sub update_last_runtime {
     my ($jobid, $type) = @_;
     lock_job_state($jobid, $type, sub {
 	my $old_state = read_job_state($jobid, $type) // $default_state;
@@ -209,6 +209,8 @@ sub get_last_runtime {
 }
 
 sub run_jobs {
+    my ($first_run) = @_;
+
     synchronize_job_states_with_config();
 
     my $jobs_cfg = cfs_read_file('jobs.cfg');
@@ -228,6 +230,10 @@ sub run_jobs {
 	    next;
 	}
 
+	# update last runtime on the first run when 'repeat-missed' is 0, so that a missed job
+	# will not start immediately after boot
+	update_last_runtime($id, $type) if $first_run && !$cfg->{'repeat-missed'};
+
 	next if defined($cfg->{enabled}) && !$cfg->{enabled}; # only schedule actually enabled jobs
 
 	my $last_run = get_last_runtime($id, $type);
diff --git a/PVE/Jobs/Plugin.pm b/PVE/Jobs/Plugin.pm
index 6098360b..76629642 100644
--- a/PVE/Jobs/Plugin.pm
+++ b/PVE/Jobs/Plugin.pm
@@ -39,6 +39,13 @@ my $defaultData = {
 	    description => "Description for the Job.",
 	    maxLength => 512,
 	},
+	'repeat-missed' => {
+	    optional => 1,
+	    type => 'boolean',
+	    description => "If true, the job will be run as soon as possible if it was missed".
+		" while the scheduler was not running.",
+	    default => 0,
+	},
     },
 };
 
diff --git a/PVE/Jobs/VZDump.pm b/PVE/Jobs/VZDump.pm
index 44fe33dc..7feb06a2 100644
--- a/PVE/Jobs/VZDump.pm
+++ b/PVE/Jobs/VZDump.pm
@@ -26,6 +26,7 @@ sub options {
 	enabled => { optional => 1 },
 	schedule => {},
 	comment => { optional => 1 },
+	'repeat-missed' => { optional => 1 },
     };
     foreach my $opt (keys %$props) {
 	if ($props->{$opt}->{optional}) {
diff --git a/PVE/Service/pvescheduler.pm b/PVE/Service/pvescheduler.pm
index f05f3bb9..40be5977 100755
--- a/PVE/Service/pvescheduler.pm
+++ b/PVE/Service/pvescheduler.pm
@@ -97,6 +97,8 @@ sub run {
 	$jobs->{$type}->{$child} = 1;
     };
 
+    my $first_run = 1;
+
     my $run_jobs = sub {
 	# TODO: actually integrate replication in PVE::Jobs and do not always fork here, we could
 	# do the state lookup and check if there's new work scheduled before doing so, e.g., by
@@ -109,8 +111,10 @@ sub run {
 	});
 
 	$fork->('jobs', sub {
-	    PVE::Jobs::run_jobs();
+	    PVE::Jobs::run_jobs($first_run);
 	});
+
+	$first_run = 0;
     };
 
     PVE::Jobs::setup_dirs();
-- 
2.30.2





  reply	other threads:[~2022-06-13 13:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-13 13:24 [pve-devel] [PATCH manager/docs v3] handle missed jobs better Dominik Csapak
2022-06-13 13:24 ` Dominik Csapak [this message]
2022-06-13 13:24 ` [pve-devel] [PATCH manager v3 2/3] fix #4053: don't run vzdump jobs when they change from disabled->enabled Dominik Csapak
2022-06-13 13:24 ` [pve-devel] [PATCH manager v3 3/3] ui: dc/Backup: add 'repeat-missed' checkbox Dominik Csapak
2022-06-13 13:24 ` [pve-devel] [PATCH docs v3 1/1] vzdump: add section about 'repeat-missed' Dominik Csapak
2022-06-17 15:34 ` [pve-devel] applied-series: [PATCH manager/docs v3] handle missed jobs better Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220613132411.3736044-2-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal