#!/usr/local/bin/perl -T

################################################################################
#
# File:    rerun
# Date:    $Date: 2008-04-06 20:13:45 -0500 (Sun, 06 Apr 2008) $
# Version: $Revision: 119 $
#
# Explicitly Mark a job that has been already been run as 'success' or
# 'failure', regardless of its original status.
#
################################################################################

use strict;
use warnings;
use Carp;
use TaskForest::LogDir;
use TaskForest::Options;
use TaskForest::Mark;
use Getopt::Long;

my $family_job_name = '';
my $log_dir_root;
my $help;
my $status = '';

my $got_options = Getopt::Long::GetOptions(
    "job=s"     => \$family_job_name,
    "log_dir=s" => \$log_dir_root,
    "status=s"  => \$status,
    "help"      => \$help,
    );


$status = lc($status);

if ($help or !$log_dir_root or !$family_job_name or ($status ne 'success' and $status ne 'failure')) {
    print "Usage: mark --job=Ff::Jj --log_dir=log_directory --status=[Success | Failure]\n\n";
    exit 1;
}


if ($family_job_name !~ /^([a-z0-9_]+)::([a-z0-9_\-]+)$/i) {
    print "Usage: rerun --job=Ff:Jj --log_dir=log_directory --status=[Success | Failure]\n\n";
    confess("\nThe --job command line argument must be of the form: Ff::Jj where\n",
            "Ff is the family name and Jj is the job name\n\n");
}
my ($family_name, $job_name) = ($1, $2);

print "Marking job $family_job_name as $status.\n";

my $log_dir      = &TaskForest::LogDir::getLogDir($log_dir_root);

&TaskForest::Mark::mark($family_name, $job_name, $log_dir, $status);

exit 0;
