#
# ./mg-anoint destroy REFKEY
#
-# ./mg-anoint anoint [ANOINT-OPTION...] REFKEY FLIGHT JOB
+# ./mg-anoint anoint [ANOINT-OPTION...] REFKEY FLIGHT JOB [REFKEY FLIGHT JOB...]
# ANOINT-OPTIONs are:
# --allow-blessed=BLESSING,... default is from `prepare'
# --allow-job-status=STATUS,... default is only `pass'
#
-# ./mg-anoint retrieve [--tolerate-unprepared] REFKEY
+# ./mg-anoint retrieve [--tolerate-unprepared] REFKEY [REFKEY...]
# => FLIGHT JOB
# if nothing anointed yet, prints nothing and exits 0
# if anointment not prepared, fails
die "unknown option $_ ?";
}
}
- die unless @ARGV==3;
- my ($refkey, $flight, $job) = @ARGV;
+ die unless @ARGV%3==0;
fail_unless_can_anoint();
prep_queries();
db_retry($dbh_tests, [], sub {
@o = ();
- $task_q->execute($refkey);
-
- # find the task row (ie, the anointment kind)
- my ($task, $refinfo) = $task_q->fetchrow_array();
- die "no such anointment kind \`$refkey' (no prepare?)\n"
- unless defined $task;
- my %params;
- foreach (split /\s+/, $refinfo) {
- die unless m/=/;
- $params{$`} = $';
- }
- my %blessings;
- $blessings{$_}++ foreach
- grep /./,
- (split /,/, $params{blessings}),
- (split /,/, $allow_blessed);
-
- my %jobstatus;
- $jobstatus{pass}++;
- $jobstatus{$_}++ foreach grep /./, split /,/, $allow_jobstatus;
-
- # check the to-be-anointed flight's blessing
- $newflight_q->execute($flight);
- my $frow = $newflight_q->fetchrow_hashref();
- die "flight $flight missing" unless $frow;
- die "flight $flight not started" unless defined $frow->{started};
-
- # check the job status
- $newjob_q->execute($flight, $job);
- my ($jstatus) = $newjob_q->fetchrow_array();
- die "job $flight.$job missing" unless defined $jstatus;
- die "job $flight.$job status $jstatus" unless $jobstatus{$jstatus};
-
- push @o, "flight $flight blessed $frow->{blessing}".
- " started ".show_abs_time($frow->{started});
-
- die "flight $flight blessing $frow->{blessing}".
- " (not $params{blessings} / $allow_blessed)"
- unless $blessings{ $frow->{blessing} };
-
- # check to-be-annointed flight is most recent
- $mostrecent_q->execute($task);
- my $mostrecent = $mostrecent_q->fetchrow_hashref();
- die "flight $flight not newer than $mostrecent->{flight}"
- unless $frow->{started} > ($mostrecent->{started} // 0);
-
- # expire old anointments
- $count_q->execute($task);
- my ($current) = $count_q->fetchrow_array();
- my $want_delete = ($current+1) - $params{keep};
- push @o, "anointment $refkey: currently $current anointed";
- if ($want_delete > 0) {
- $todelete_q->execute($task, $want_delete);
- while (my $d = $todelete_q->fetchrow_hashref()) {
- push @o, " expiring $d->{flight}.$d->{job} [/$d->{shareix}]".
- " started ".show_abs_time($d->{started});
- $delete_res_q->execute($task, $d->{flight}, $d->{shareix});
- }
- }
- # at last!
- $insert_q->execute($flight,$task,$task,$job);
- push @o, "anointed $flight.$job";
+ for (my $i=0; $i < @ARGV; $i+=3) {
+ my ($refkey, $flight, $job) = @ARGV[$i..$i+2];
+
+ $task_q->execute($refkey);
+
+ # find the task row (ie, the anointment kind)
+ my ($task, $refinfo) = $task_q->fetchrow_array();
+ die "no such anointment kind \`$refkey' (no prepare?)\n"
+ unless defined $task;
+ my %params;
+ foreach (split /\s+/, $refinfo) {
+ die unless m/=/;
+ $params{$`} = $';
+ }
+ my %blessings;
+ $blessings{$_}++ foreach
+ grep /./,
+ (split /,/, $params{blessings}),
+ (split /,/, $allow_blessed);
+
+ my %jobstatus;
+ $jobstatus{pass}++;
+ $jobstatus{$_}++ foreach grep /./, split /,/, $allow_jobstatus;
+
+ # check the to-be-anointed flight's blessing
+ $newflight_q->execute($flight);
+ my $frow = $newflight_q->fetchrow_hashref();
+ die "flight $flight missing" unless $frow;
+ die "flight $flight not started" unless defined $frow->{started};
+
+ # check the job status
+ $newjob_q->execute($flight, $job);
+ my ($jstatus) = $newjob_q->fetchrow_array();
+ die "job $flight.$job missing" unless defined $jstatus;
+ die "job $flight.$job status $jstatus" unless $jobstatus{$jstatus};
+
+ push @o, "flight $flight blessed $frow->{blessing}".
+ " started ".show_abs_time($frow->{started});
+
+ die "flight $flight blessing $frow->{blessing}".
+ " (not $params{blessings} / $allow_blessed)"
+ unless $blessings{ $frow->{blessing} };
+
+ # check to-be-annointed flight is most recent
+ $mostrecent_q->execute($task);
+ my $mostrecent = $mostrecent_q->fetchrow_hashref();
+ die "flight $flight not newer than $mostrecent->{flight}"
+ unless $frow->{started} > ($mostrecent->{started} // 0);
+
+ # expire old anointments
+ $count_q->execute($task);
+ my ($current) = $count_q->fetchrow_array();
+ my $want_delete = ($current+1) - $params{keep};
+ push @o, "anointment $refkey: currently $current anointed";
+ if ($want_delete > 0) {
+ $todelete_q->execute($task, $want_delete);
+ while (my $d = $todelete_q->fetchrow_hashref()) {
+ push @o, " expiring $d->{flight}.$d->{job} [/$d->{shareix}]".
+ " started ".show_abs_time($d->{started});
+ $delete_res_q->execute($task, $d->{flight}, $d->{shareix});
+ }
+ }
+
+ # at last!
+ $insert_q->execute($flight,$task,$task,$job);
+ push @o, "anointed $flight.$job";
+ }
});
pr_o();
}
shift @ARGV;
$tolerate_unprepared = 1;
}
- die unless @ARGV==1;
+ die unless @ARGV>=1;
die if $ARGV[0] =~ m/^-/;
- my ($refkey) = @ARGV;
empty_unless_can_anoint();
prep_queries();
db_retry($dbh_tests, [], sub {
@o = ();
- $task_q->execute($refkey);
- my ($task) = $task_q->fetchrow_array();
- die "no such anointment kind \`$refkey'"
- unless defined $task or $tolerate_unprepared;
-
- $mostrecent_q->execute($task);
- my $row = $mostrecent_q->fetchrow_hashref();
- if ($row) {
- push @o, "$row->{flight} $row->{job}";
- } else {
- print STDERR "warning: nothing anointed $refkey\n";
+
+ foreach my $refkey (@ARGV) {
+ $task_q->execute($refkey);
+ my ($task) = $task_q->fetchrow_array();
+ die "no such anointment kind \`$refkey'"
+ unless defined $task or $tolerate_unprepared;
+
+ $mostrecent_q->execute($task);
+ my $row = $mostrecent_q->fetchrow_hashref();
+ if ($row) {
+ push @o, "$row->{flight} $row->{job}";
+ } else {
+ # Push an error line so the number of output lines
+ # matches the number of REFKEYs requested.
+ push @o, "ERROR";
+ print STDERR "warning: nothing anointed $refkey\n";
+ }
}
});
pr_o();