Tasks: only execute the event if the plugin is interested in it

This commit is contained in:
Graham Christensen
2021-12-20 13:27:59 -05:00
parent 633fc36d6a
commit a14501c616
12 changed files with 150 additions and 21 deletions

View File

@ -38,6 +38,12 @@ sub new_event {
}, $self;
}
sub interested {
my ($self, $plugin) = @_;
return $self->{"event"}->interestedIn($plugin);
}
sub execute {
my ($self, $db, $plugin) = @_;
return $self->{"event"}->execute($db, $plugin);

View File

@ -27,6 +27,11 @@ sub new {
}, $self;
}
sub interestedIn {
my ($self, $plugin) = @_;
return int(defined($plugin->can('buildFinished')));
}
sub load {
my ($self, $db) = @_;

View File

@ -25,6 +25,11 @@ sub new {
}, $self;
}
sub interestedIn {
my ($self, $plugin) = @_;
return int(defined($plugin->can('buildQueued')));
}
sub load {
my ($self, $db) = @_;

View File

@ -25,6 +25,11 @@ sub new {
}, $self;
}
sub interestedIn {
my ($self, $plugin) = @_;
return int(defined($plugin->can('buildStarted')));
}
sub load {
my ($self, $db) = @_;

View File

@ -34,6 +34,11 @@ sub new :prototype($$$) {
}, $self;
}
sub interestedIn {
my ($self, $plugin) = @_;
return int(defined($plugin->can('stepFinished')));
}
sub load {
my ($self, $db) = @_;

View File

@ -25,29 +25,35 @@ sub instantiate {
return @$plugins;
}
# Called when build $build has been queued.
sub buildQueued {
my ($self, $build) = @_;
}
# To implement behaviors in response to the following events, implement
# the function in your plugin and it will be executed by hydra-notify.
#
# See the tests in t/Event/*.t for arguments, and the documentation for
# notify events for semantics.
#
# # Called when build $build has been queued.
# sub buildQueued {
# my ($self, $build) = @_;
# }
# Called when build $build has started.
sub buildStarted {
my ($self, $build) = @_;
}
# # Called when build $build has started.
# sub buildStarted {
# my ($self, $build) = @_;
# }
# Called when build $build has finished. If the build failed, then
# $dependents is an array ref to a list of builds that have also
# failed as a result (i.e. because they depend on $build or a failed
# dependeny of $build).
sub buildFinished {
my ($self, $build, $dependents) = @_;
}
# # Called when build $build has finished. If the build failed, then
# # $dependents is an array ref to a list of builds that have also
# # failed as a result (i.e. because they depend on $build or a failed
# # dependeny of $build).
# sub buildFinished {
# my ($self, $build, $dependents) = @_;
# }
# Called when step $step has finished. The build log is stored in the
# file $logPath (bzip2-compressed).
sub stepFinished {
my ($self, $step, $logPath) = @_;
}
# # Called when step $step has finished. The build log is stored in the
# # file $logPath (bzip2-compressed).
# sub stepFinished {
# my ($self, $step, $logPath) = @_;
# }
# Called to determine the set of supported input types. The plugin
# should add these to the $inputTypes hashref, e.g. $inputTypes{'svn'}

View File

@ -14,7 +14,6 @@ use Data::Dumper;
my $CONFIG_SECTION = "git-input";
sub supportedInputTypes {
my ($self, $inputTypes) = @_;
$inputTypes->{'git'} = 'Git checkout';

View File

@ -117,6 +117,11 @@ sub new {
type => "counter",
help => "Number of tasks that have not been processed because the plugin does not exist."
);
$prometheus->declare(
"notify_plugin_not_interested",
type => "counter",
help => "Number of tasks that have not been processed because the plugin was not interested in the event."
);
my %plugins_by_name = map { ref $_ => $_ } @{$plugins};
@ -190,6 +195,11 @@ sub dispatch_task {
return 0;
}
if (!$task->{"event"}->interested($plugin)) {
$self->{"prometheus"}->inc("notify_plugin_not_interested", $event_labels);
return 0;
}
$self->{"prometheus"}->inc("notify_plugin_executions", $event_labels);
eval {
my $start_time = [gettimeofday()];