From 044edfb7649844dd11026c50d785758a222f59f5 Mon Sep 17 00:00:00 2001 From: Rob Vermaas Date: Fri, 18 Dec 2009 12:07:45 +0000 Subject: [PATCH] * email notification of evaluation errors to project owner (if desired) --- src/lib/Hydra/Schema/Users.pm | 6 +++-- src/script/hydra_scheduler.pl | 43 ++++++++++++++++++++++++++++++++++- src/sql/hydra.sql | 3 ++- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/lib/Hydra/Schema/Users.pm b/src/lib/Hydra/Schema/Users.pm index 0481d935..517b3b51 100644 --- a/src/lib/Hydra/Schema/Users.pm +++ b/src/lib/Hydra/Schema/Users.pm @@ -39,6 +39,8 @@ __PACKAGE__->add_columns( is_nullable => 0, size => undef, }, + "emailonerror", + { data_type => "integer", default_value => 0, is_nullable => 0, size => undef }, ); __PACKAGE__->set_primary_key("username"); __PACKAGE__->has_many( @@ -53,8 +55,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.04999_09 @ 2009-11-17 16:04:13 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:oBiKpCxHGZcGujhY/ZbbxA +# Created by DBIx::Class::Schema::Loader v0.04999_09 @ 2009-12-18 12:57:04 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:/AWZnceSVTAlb5Tru9T1+g # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/src/script/hydra_scheduler.pl b/src/script/hydra_scheduler.pl index f14e1e37..0351a3cb 100755 --- a/src/script/hydra_scheduler.pl +++ b/src/script/hydra_scheduler.pl @@ -7,11 +7,18 @@ use Hydra::Helper::Nix; use Hydra::Helper::AddBuilds; use Digest::SHA qw(sha256_hex); +use Email::Sender::Simple qw(sendmail); +use Email::Sender::Transport::SMTP; +use Email::Simple; +use Email::Simple::Creator; +use Sys::Hostname::Long; +use Config::General; + STDOUT->autoflush(); my $db = openHydraDB; - +my %config = new Config::General($ENV{"HYDRA_CONFIG"})->getall; sub fetchInputs { my ($project, $jobset, $inputInfo) = @_; @@ -31,8 +38,42 @@ sub setJobsetError { $jobset->update({errormsg => $errorMsg, errortime => time}); }); }; + sendJobsetErrorNotification($jobset, $errorMsg); } +sub sendJobsetErrorNotification() { + my ($jobset, $errorMsg) = @_; + + return if $jobset->project->owner->emailonerror == 0; + + my $projectName = $jobset->project->name; + my $jobsetName = $jobset->name; + + my $sender = $config{'notification_sender'} || + (($ENV{'USER'} || "hydra") . "@" . hostname_long); + + my $body = "Hi,\n" + . "\n" + . "This is to let you know that Hydra jobset evalation of $projectName:$jobsetName " + . "resulted in the following error:\n" + . "\n" + . "$errorMsg" + . "\n" + . "Regards,\n\nThe Hydra build daemon.\n"; + + my $email = Email::Simple->create( + header => [ + To => $jobset->project->owner->emailaddress, + From => "Hydra Build Daemon <$sender>", + Subject => "Hydra $projectName:$jobsetName evaluation error", + ], + body => $body, + ); + + print $email->as_string if $ENV{'HYDRA_MAIL_TEST'}; + + sendmail($email); +} sub permute { my @list = @_; diff --git a/src/sql/hydra.sql b/src/sql/hydra.sql index 3e3d6c9b..32cc4c84 100644 --- a/src/sql/hydra.sql +++ b/src/sql/hydra.sql @@ -2,7 +2,8 @@ create table Users ( userName text primary key not null, fullName text, emailAddress text not null, - password text not null -- sha256 hash + password text not null, -- sha256 hash + emailOnError integer not null default 0 );