Added rerun_problem and improved gm rerun
authorSergiu <srg.pscs@gmail.com>
Sat, 6 Feb 2016 20:12:13 +0000 (22:12 +0200)
committerMarius Gavrilescu <marius@ieval.ro>
Fri, 12 Feb 2016 18:18:43 +0000 (18:18 +0000)
lib/Gruntmaster/App/Command/Rerun.pm
lib/Gruntmaster/Data.pm

index bb4c0c8c6cb1d6928eb6bc82b563982c804536db..4856b33b0ac661fa0937e2d9405a357d152a8374 100644 (file)
@@ -7,20 +7,28 @@ our $VERSION = '5999.000_015';
 
 use Gruntmaster::App '-command';
 use Gruntmaster::Data;
+use Scalar::Util qw/looks_like_number/;
 
-sub usage_desc { '%c rerun id' }
+sub usage_desc { '%c rerun id...' }
 
 sub validate_args {
        my ($self, $opt, $args) = @_;
        my @args = @$args;
-       $self->usage_error('This command only works on jobs') if $self->app->table && $self->app->table ne 'jobs';
-       $self->usage_error('Wrong number of arguments') if @args != 1;
+       $self->usage_error('Not enough arguments') if @args < 1;
 }
 
 sub execute {
        my ($self, $opt, $args) = @_;
-       my ($obj) = @$args;
-       rerun_job $obj;
+       my @args = @$args;
+
+       for my $obj (@args) {
+               if (looks_like_number $obj) {
+                       rerun_job $obj;
+               }
+               else {
+                       rerun_problem $obj;
+               }
+       }
 }
 
 1;
@@ -30,16 +38,19 @@ __END__
 
 =head1 NAME
 
-Gruntmaster::App::Command::Rerun - rerun a job
+Gruntmaster::App::Command::Rerun - rerun some jobs and probles
 
 =head1 SYNOPSIS
 
-  gm rerun 123
+  gm rerun 123 124
+
+  gm rerun aplusb aminusb
+
+  gm rerun 12 aplusb
 
 =head1 DESCRIPTION
 
-The rerun command takes the ID of a job, clears its result, and makes
-B<gruntmaster-daemon> rerun it.
+The rerun command takes some IDs of jobs and problems and reruns them.
 
 =head1 SEE ALSO
 
index d54f17bed7914dea9d42e0a7992bf6da1a4388c6..da2b3c59eb50851a3935f1fc95118b654cbb09d6 100644 (file)
@@ -36,6 +36,7 @@ my %statements = (
 
        job_entry_sth => 'SELECT * FROM job_entry WHERE id = ?',
 
+       rerun_problem_sth => 'UPDATE jobs SET daemon=NULL,result=-2,result_text=NULL,results=NULL,errors=NULL WHERE problem = ?',
        rerun_job_sth => 'UPDATE jobs SET daemon=NULL,result=-2,result_text=NULL,results=NULL,errors=NULL WHERE id = ?',
        take_job_sth => 'UPDATE jobs SET daemon=? WHERE id = (SELECT id FROM jobs WHERE daemon IS NULL LIMIT 1 FOR UPDATE) RETURNING id',
 );
@@ -242,6 +243,12 @@ sub update_status {
        $db->commit
 }
 
+sub rerun_problem {
+       my ($problem) = @_;
+       _query rerun_problem_sth => $problem;
+       purge '/log/';
+}
+
 sub rerun_job {
        my ($id) = @_;
        _query rerun_job_sth => $id;
This page took 0.015098 seconds and 4 git commands to generate.