12 use CXGN
::ITAG
::Pipeline
;
13 use CXGN
::Tools
::List qw
/distinct/;
18 my $message = shift || '';
19 $message = "Error: $message\n" if $message;
23 $FindBin::Script -d itag_dir email_address
25 Scans ITAG pipeline repository for changes, emails the given email
26 address about them if it hasn't already.
28 Uses .email_log files in the pipeline repository to log what it's
29 already emailed about.
34 REQUIRED: base directory to search for ITAG pipelines.
38 sub HELP_MESSAGE
{usage
()}
41 getopts
('d:',\
%opt) or usage
();
44 my ($itag_email) = @ARGV;
45 die "must provide an email address\n"
47 die "invalid email address '$itag_email'\n"
48 unless $itag_email =~ /^\w+@[\w\.]+\w$/;
50 my $pipe = CXGN
::ITAG
::Pipeline
->open( basedir
=> $opt{d
} );
53 our $log = CXGN
::IndexedLog
->open( File
=> $pipe->email_log_filename );
55 #now go through all the things we might send an email about, check
56 #that we haven't already sent an email about it yet, then send a
57 #single email telling about all the things that happened to the
60 our @email_descriptions;
65 my ($tagwords, $summary, $message, $logmessage) = @_;
67 $logmessage ||= $message;
68 $logmessage = "$tagwords $logmessage";
69 my %entry = $log->lookup( content
=> $tagwords );
71 return if %entry && $entry{content
} eq $logmessage;
73 push @email_descriptions, $message;
74 push @email_summaries, $summary;
75 push @log_appends, $logmessage;
78 #send about a new pipeline
79 send_if_needed
('NEW_PIPELINE '.$pipe->version, 'new pipeline version', "NEW PIPELINE VERSION ".$pipe->version." created");
81 #send about new batches
82 foreach my $bn ($pipe->list_batches) {
83 my $batch = $pipe->batch($bn);
84 my $seq_cnt = $batch->seqlist;
85 send_if_needed
("NEW_BATCH $bn", 'new batch', "NEW BATCH $bn created containing $seq_cnt sequences");
87 #send about new analysis state changes
88 foreach my $tag ($pipe->list_analyses) {
89 my $an = $pipe->analysis($tag);
90 my $status = $an->status($batch);
91 my $pipever = $pipe->version;
92 if( $status eq 'ready' ) {
93 send_if_needed
("ASTATE $bn:$tag",'analyses ready', "analysis $tag is ready to run in batch $bn","ready");
95 elsif( $status eq 'error' ) {
96 send_if_needed
("ASTATE $bn:$tag",'errors', "analysis $tag has problems in batch $bn, see http://sgn.cornell.edu/sequencing/itag/status_html.pl?pipe=$pipever&batch=$bn for details","error");
101 if( @email_descriptions ) {
102 my $action_string = join '', map "* $_\n", @email_descriptions;
103 my $email_body = <<EOM;
104 This is the ITAG pipeline management system, informing you of the following:
110 The ITAG Pipeline Managment System
112 sendmail
( From
=> 'itagpipeline@upload.sgn.cornell.edu',
114 Subject
=> 'status - '.join(', ',distinct
@email_summaries),
117 # warn "sent email:\n".$email_body;
120 # warn "no changes detected, no email sent\n";
123 $log->append($_) foreach @log_appends;