ensembl-hive  2.5
SlackNotification.pm
Go to the documentation of this file.
1 =pod
2 
3 =head1 NAME
4 
6 
7 =head1 SYNOPSIS
8 
9  This is a RunnableDB module that implements Bio::EnsEMBL::Hive::Process interface
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.
12 
13  Please refer to Bio::EnsEMBL::Hive::Process documentation to understand the basics of the RunnableDB interface.
14 
15  Please refer to Bio::EnsEMBL::Hive::PipeConfig::* pipeline configuration files to understand how to configure pipelines.
16 
17 =head1 DESCRIPTION
18 
19  This RunnableDB module will send a notification to a Slack channel.
20  You can either dataflow into it, or simply create standalone jobs.
21 
22  It requires "slack_webhook" to be defined. You can this in the parameters of your Slack team.
23  The message itself is defined by the "text" parameter (and optionally by "attachments" too).
24 
25 =head1 LICENSE
26 
27  Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
28  Copyright [2016-2022] EMBL-European Bioinformatics Institute
29 
30  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
31  You may obtain a copy of the License at
32 
33  http://www.apache.org/licenses/LICENSE-2.0
34 
35  Unless required by applicable law or agreed to in writing, software distributed under the License
36  is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
37  See the License for the specific language governing permissions and limitations under the License.
38 
39 =head1 CONTACT
40 
41  Please subscribe to the Hive mailing list: http://listserver.ebi.ac.uk/mailman/listinfo/ehive-users to discuss Hive-related questions or to be notified of our updates
42 
43 =cut
44 
45 
46 package Bio::EnsEMBL::Hive::RunnableDB::SlackNotification;
47 
48 use strict;
49 use warnings;
50 
51 use Bio::EnsEMBL::Hive::Utils::Slack ('send_message_to_slack');
52 
53 use base ('Bio::EnsEMBL::Hive::Process');
54 
55 sub param_defaults {
56  return {
57 
58  # These parameters have a default value in the webhook, but can be overriden here
59  'channel' => undef,
60  'username' => undef,
61  'icon_url' => undef,
62  'icon_emoji' => undef, # wins if both icon_* parameters are defined
63 
64  # If the sender wants something more fancy than a paragraph
65  'attachments' => undef,
66  };
67 }
68 
69 sub run {
70  my $self = shift;
71 
72  my $payload = {};
73 
74  # required arguments
75  foreach my $k (qw(text)) {
76  $payload->{$k} = $self->param_required($k);
77  }
78 
79  # optional arguments
80  foreach my $k (qw(username channel icon_emoji icon_url attachments)) {
81  $payload->{$k} = $self->param($k) if $self->param($k);
82  }
83 
84  send_message_to_slack($self->param_required('slack_webhook'), $payload);
85 }
86 
87 1;