https://github.com/genome/genome
Revision 80b7ba21596ab23105cc80e4c510d60336c7ade7 authored by Thomas B. Mooney on 06 March 2017, 16:52:12 UTC, committed by GitHub on 06 March 2017, 16:52:12 UTC
2 parent s 702f2a0 + 0a05ec7
Raw File
Tip revision: 80b7ba21596ab23105cc80e4c510d60336c7ade7 authored by Thomas B. Mooney on 06 March 2017, 16:52:12 UTC
Merge pull request #43 from tmooney/remove_aramu_from_notify_list
Tip revision: 80b7ba2
pend-alert
#!/usr/bin/perl

use strict;
use warnings;

use Data::Dumper;
use IPC::System::Simple qw(capture);
use Scalar::Util qw(looks_like_number);
use Time::Piece qw();
use Text::Table qw();

my $max_seconds = shift @ARGV;
unless (looks_like_number($max_seconds)) {
    print STDERR "not a number: $max_seconds\n";
    exit 1;
}

my @bjobs = capture('bjobsw', '-nsTjqJ', @ARGV);
chomp @bjobs;

my $dt_pattern = '%y/%m/%d-%H:%M:%S';
my $now = Time::Piece->localtime();

my $table = Text::Table->new('ID', 'Age', 'Status', 'Queue', 'Name');
my @found;
for my $bjob (@bjobs) {
    my ($status, $submit_time, $job_id, $job_queue, $job_name) = split(/\t/, $bjob);
    next if $status eq 'RUN';
    next if $submit_time eq '-';

    # LSF doesn't show year
    $submit_time = $now->yy . '/' . $submit_time;
    $submit_time = Time::Piece->strptime($submit_time, $dt_pattern);
    if ($submit_time > $now) {
        $submit_time->add_years(-1);
    }

    my $elapsed_seconds = $now - $submit_time;

    # Time::Piece accounts for time zone in difference but provides no means for
    # us to tell it that $submit_time is in local time zone (strptime ignored
    # timezone).  You could reach into object to turn on the "is_local" bit but
    # that could change.
    if ($now->tzoffset != $submit_time->tzoffset && $submit_time->tzoffset == 0) {
        $elapsed_seconds += $now->tzoffset;
    }

    if ($elapsed_seconds >= $max_seconds) {
        $table->add($job_id, $elapsed_seconds, $status, $job_queue, $job_name);
    }
}

if ($table->body_height) {
    print join("\n", "Found non-running jobs older than $max_seconds seconds."), "\n\n";
    print $table;
    print "\nPlease check on these jobs and see if they can be expedited.  For example, if they are in the alignment-pd queue you might try moving them to the apipe queue.\n";
    exit 1;
} elsif (@bjobs) {
    print "No non-running jobs older than $max_seconds seconds.\n";
}
back to top