10 and is ran by Workers during the execution of eHive pipelines.
11 It is not generally supposed to be instantiated and used outside of
this framework.
19 This RunnableDB module will send you a
short notification email message per
20 each job. You can either dataflow into it, or simply create standalone
23 The
main body of the email is expected in the
"text" parameter. If the
24 "is_html" parameter is set, the body is expected to be in HTML.
26 Attachments such as diagrams, images, PDFs have to be listed in the
27 'attachments' parameter.
29 C<format_table> provides a simple method to stringify a table of data. If
30 you need more options to control the separators, the alignment, etc, have a
31 look at the very comprehensive L<Text::Table>.
33 Note:
this module uses L<Email::Sender> to send the email, which by
default
34 uses C<sendmail> but has other backends configured. As such, it depends
35 heavily on the implementation of your compute farm. Please make sure it
36 works as intended before
using this module in complex pipelines.
40 Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
41 Copyright [2016-2024] EMBL-European Bioinformatics Institute
43 Licensed under the Apache License,
Version 2.0 (the
"License"); you may not use
this file except in compliance with the License.
44 You may obtain a copy of the License at
48 Unless required by applicable law or agreed to in writing, software distributed under the License
49 is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
50 See the License
for the specific language governing permissions and limitations under the License.
54 Please subscribe to the
Hive mailing list: http:
59 package Bio::EnsEMBL::Hive::RunnableDB::NotifyByEmail;
66 use base (
'Bio::EnsEMBL::Hive::Process');
71 'subject' =>
'An automatic message from your pipeline',
79 Description : Implements fetch_input()
interface method of
Bio::EnsEMBL::Hive::Process that is used to read in parameters and load data.
80 Here we have nothing to do.
89 Description : Implements
run()
interface method of
Bio::EnsEMBL::Hive::Process that is used to perform the
main bulk of the job (minus input and output).
90 Here the actual sending of the email message happens in
run() though one may argue it is technically 'output'.
92 param('email'): The email address to send the message to.
94 param('subject'): The (optional) 'Subject:' line.
96 param('text'): Text of the email message. It will undergo parameter substitution.
98 param('is_html'): Boolean. Whether the content of 'text' is in HTML
100 param('attachments'): Array of paths for files to attach.
102 param('*'): Any other parameters can be freely used for parameter substitution.
109 my $email = $self->param_required(
'email');
110 my $subject = $self->param_required(
'subject');
111 my $text = $self->param_required(
'text');
112 my $attachments = $self->param(
'attachments');
114 my $msg = Email::Stuffer->from($email)
118 if ($self->param(
'is_html')) {
119 $msg->html_body($text);
121 $msg->text_body($text);
124 if ($attachments and @$attachments) {
125 $msg->attach_file($_)
for @$attachments;
133 Description : Implements write_output()
interface method of
Bio::EnsEMBL::Hive::Process that is used to deal with job's output after the execution.
134 Here we have nothing to do.
143 ######################
144 ## Internal methods ##
145 ######################
147 # Present data in a nice table, like what mySQL does.
152 The same type of table could be generated with L<Text::Table>:
154 my $first_column_name = shift @$columns;
155 my $tb = Text::Table->new(\
'| ', $first_column_name, (
map { +(\
' | ', $_) } @$columns), \
' |',);
156 $tb->load(@$results);
157 my $rule = $tb->rule(
'-',
'+');
158 return $title .
"\n" . $rule . $tb->title() . $rule . $tb->body() . $rule;
163 my ($self, $title, $columns, $results) = @_;
166 foreach (@$columns) {
167 push @lengths, length($_) + 2;
170 foreach (@$results) {
171 for (my $i=0; $i < scalar(@$_); $i++) {
172 my $len = length($$_[$i]
173 $lengths[$i] = $len
if $len > $lengths[$i];
177 my $table =
"$title\n";
178 $table .=
'+'.join(
'+',
map {
'-' x $_ } @lengths).
'+'.
"\n";
180 for (my $i=0; $i < scalar(@lengths); $i++) {
181 my $column = $$columns[$i];
182 my $padding = $lengths[$i] - length($column) - 2;
183 $table .=
'| '.$column.(
' ' x $padding).
' ';
186 $table .=
'|'.
"\n".
'+'.join(
'+',
map {
'-' x $_ } @lengths).
'+'.
"\n";
188 foreach (@$results) {
189 for (my $i=0; $i < scalar(@lengths); $i++) {
191 my $padding = $lengths[$i] - length($value) - 2;
192 $table .=
'| '.$value.(
' ' x $padding).
' ';
197 $table .=
'+'.join(
'+',
map {
'-' x $_ } @lengths).
'+'.
"\n";