#!/usr/bin/perl
# $Id: oarresume,v 1.9 2005/05/04 13:03:36 capitn Exp $
# resume a job --> it will be rescheduled

use strict;
use warnings;
use Data::Dumper;
use DBI();
use oar_iolib;
use IO::Socket::INET;
use oar_conflib qw(init_conf dump_conf get_conf is_conf);

#my $remote_host = "icluster4.imag.fr";
#my $remote_port = "6666";

sub usage {
    print STDERR "usage: qresume [idJob]\n";
    exit 1;
}

init_conf("oar.conf");
my $remote_host = get_conf("SERVER_HOSTNAME");
my $remote_port = get_conf("SERVER_PORT");

usage if (@ARGV < 1);

my $idJob = $ARGV[0];
print "idJob = $idJob\n";

my $base = iolib::connect();
my $err = iolib::resume_job($base,$idJob);
iolib::disconnect($base);

if ($err != 0) {
    print STDERR "Can't resume $idJob error = $err\n";
    exit 1;
}

#Signal Almigthy

my $socket = IO::Socket::INET->new(PeerAddr => $remote_host,
             PeerPort => $remote_port,
                         Proto => "tcp",
                         Type  => SOCK_STREAM)
            or die "Couldn't connect executor $remote_host:$remote_port\n";

print $socket "Qresume\n";

#my $answer=<$socket>;

#print "Almigthy answers : $answer\n";

exit 0;
