Add Remote Destination column to Active Cron Schedules table

Split cron_to_human() to return timing and remotes separately.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
shuki
2026-03-04 05:08:45 +02:00
parent db1b10ffb3
commit 92c3428f89
2 changed files with 11 additions and 15 deletions

View File

@@ -59,12 +59,14 @@ print qq{<div class="card bg-base-100 shadow-sm border border-base-300 mb-6">\n<
print qq{<h2 class="card-title text-sm">Active Cron Schedules</h2>\n}; print qq{<h2 class="card-title text-sm">Active Cron Schedules</h2>\n};
if (keys %$schedules) { if (keys %$schedules) {
print qq{<div class="overflow-x-auto rounded-box border border-base-content/5 bg-base-100"><table class="table">\n}; print qq{<div class="overflow-x-auto rounded-box border border-base-content/5 bg-base-100"><table class="table">\n};
print qq{<thead><tr><th>Schedule</th><th>Timing</th></tr></thead>\n}; print qq{<thead><tr><th>Schedule</th><th>Timing</th><th>Remote Destination</th></tr></thead>\n};
print qq{<tbody>\n}; print qq{<tbody>\n};
for my $name (sort keys %$schedules) { for my $name (sort keys %$schedules) {
my $esc_name = GnizaWHM::UI::esc($name); my $esc_name = GnizaWHM::UI::esc($name);
my $human = GnizaWHM::UI::esc(GnizaWHM::Cron::cron_to_human($schedules->{$name})); my ($timing, $remotes) = GnizaWHM::Cron::cron_to_human($schedules->{$name});
print qq{<tr class="hover"><td>$esc_name</td><td>$human</td></tr>\n}; my $esc_timing = GnizaWHM::UI::esc($timing);
my $esc_remotes = GnizaWHM::UI::esc($remotes);
print qq{<tr class="hover"><td>$esc_name</td><td>$esc_timing</td><td>$esc_remotes</td></tr>\n};
} }
print qq{</tbody>\n</table></div>\n}; print qq{</tbody>\n</table></div>\n};
} else { } else {

View File

@@ -111,14 +111,15 @@ sub remove_schedule {
} }
# cron_to_human($cron_line) # cron_to_human($cron_line)
# Converts a gniza cron line to a human-readable description. # Converts a gniza cron line to human-readable timing and remotes.
# e.g. "0 * * * * /usr/local/bin/gniza backup --remote=rasp ..." => "Every hour, to rasp" # Returns ($timing, $remotes) in list context.
# e.g. "0 * * * * /usr/local/bin/gniza backup --remote=rasp ..." => ("Every hour", "rasp")
sub cron_to_human { sub cron_to_human {
my ($cron_line) = @_; my ($cron_line) = @_;
# Extract the 5 cron fields # Extract the 5 cron fields
my @parts = split /\s+/, $cron_line, 6; my @parts = split /\s+/, $cron_line, 6;
return $cron_line if @parts < 6; return ($cron_line, '') if @parts < 6;
my ($min, $hour, $dom, $mon, $dow) = @parts[0..4]; my ($min, $hour, $dom, $mon, $dow) = @parts[0..4];
# Build timing description # Build timing description
@@ -126,20 +127,16 @@ sub cron_to_human {
my @dow_names = qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday); my @dow_names = qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday);
if ($hour eq '*' && $dom eq '*' && $mon eq '*' && $dow eq '*') { if ($hour eq '*' && $dom eq '*' && $mon eq '*' && $dow eq '*') {
# Hourly
$timing = 'Every hour'; $timing = 'Every hour';
} }
elsif ($dom eq '*' && $mon eq '*' && $dow eq '*') { elsif ($dom eq '*' && $mon eq '*' && $dow eq '*') {
# Daily
$timing = sprintf('Daily at %02d:%02d', $hour, $min); $timing = sprintf('Daily at %02d:%02d', $hour, $min);
} }
elsif ($dom eq '*' && $mon eq '*' && $dow =~ /^[0-6]$/) { elsif ($dom eq '*' && $mon eq '*' && $dow =~ /^[0-6]$/) {
# Weekly
my $day_name = $dow_names[$dow] // "day $dow"; my $day_name = $dow_names[$dow] // "day $dow";
$timing = sprintf('Every %s at %02d:%02d', $day_name, $hour, $min); $timing = sprintf('Every %s at %02d:%02d', $day_name, $hour, $min);
} }
elsif ($mon eq '*' && $dow eq '*' && $dom =~ /^\d+$/) { elsif ($mon eq '*' && $dow eq '*' && $dom =~ /^\d+$/) {
# Monthly
my $suffix = ($dom == 1 || $dom == 21 || $dom == 31) ? 'st' my $suffix = ($dom == 1 || $dom == 21 || $dom == 31) ? 'st'
: ($dom == 2 || $dom == 22) ? 'nd' : ($dom == 2 || $dom == 22) ? 'nd'
: ($dom == 3 || $dom == 23) ? 'rd' : ($dom == 3 || $dom == 23) ? 'rd'
@@ -151,15 +148,12 @@ sub cron_to_human {
} }
# Extract target remotes from --remote= flag # Extract target remotes from --remote= flag
my $remotes = ''; my $remotes = 'All';
if ($cron_line =~ /--remote=(\S+)/) { if ($cron_line =~ /--remote=(\S+)/) {
$remotes = $1; $remotes = $1;
} }
if ($remotes ne '') { return ($timing, $remotes);
return "$timing, to $remotes";
}
return "$timing, all remotes";
} }
# -- Private -- # -- Private --