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

[?]
Dec 20, 2021, 6:27 PM
USGMELC3GV3KAOQXVKC7XLSLF5UXA7DHI77CX7STJ2BPR5MDRTFAC

Dependencies

  • [2] 34SOPSVF Allow to configure the timeout value for the GitInput plugin in different places.
  • [3] LM2LEJNH hydra-notify: listen for build_queued events
  • [4] 6HMHT4IQ TaskDispatcher: pre-declare the notify_no_such_plugin metric
  • [5] CKYPPACO Hopefully fix UTF-8 chars in Hipchat notification messages
  • [6] BLVQGJ4L Use OO-style plugins
  • [7] FCTX433O Add buildStarted plugin hook
  • [8] NTEDD7T4 Provide a plugin hook for when build steps finish
  • [9] 5EQYVRWE Add a plugin mechanism
  • [10] JAH3UPWA Support revision control systems via plugins
  • [11] PXTSKX4G Add buildQueued plugin hook
  • [12] 7EGUBBRQ Lock paths in the scm cache
  • [*] EKHD4I44 Event: init structure and parse existing messages
  • [*] T3OHZDYP hydra-notify: move BuildFinished processing to an Event
  • [*] OPSWSU4L hydra-notify: move BuildStarted processing to an Event
  • [*] LQEYBAEL hydra-notify: move StepFinished processing to an Event
  • [*] GQGQEMMA Event.pm: add a new_event helper to parse and construct an Event
  • [*] SWXGVPJN hydra-notify: extract runPluginsForEvent to a TaskDispatcher

Change contents

  • edit in src/lib/Hydra/Event/BuildFinished.pm at line 30
    [15.214]
    [15.214]
    sub interestedIn {
    my ($self, $plugin) = @_;
    return int(defined($plugin->can('buildFinished')));
    }
  • edit in src/lib/Hydra/Event/BuildQueued.pm at line 28
    [3.569]
    [3.569]
    sub interestedIn {
    my ($self, $plugin) = @_;
    return int(defined($plugin->can('buildQueued')));
    }
  • edit in src/lib/Hydra/Event/BuildStarted.pm at line 28
    [16.88]
    [16.88]
    sub interestedIn {
    my ($self, $plugin) = @_;
    return int(defined($plugin->can('buildStarted')));
    }
  • edit in src/lib/Hydra/Event/StepFinished.pm at line 37
    [17.211]
    [17.211]
    sub interestedIn {
    my ($self, $plugin) = @_;
    return int(defined($plugin->can('stepFinished')));
    }
  • edit in src/lib/Hydra/Event.pm at line 39
    [18.231]
    [14.2933]
    }
    sub interested {
    my ($self, $plugin) = @_;
    return $self->{"event"}->interestedIn($plugin);
  • edit in src/lib/Hydra/Plugin/GitInput.pm at line 17
    [5.5041][2.63:64]()
  • replacement in src/lib/Hydra/Plugin.pm at line 28
    [5.6015][5.45:138]()
    # Called when build $build has been queued.
    sub buildQueued {
    my ($self, $build) = @_;
    }
    [5.6015]
    [5.138]
    # 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) = @_;
    # }
  • replacement in src/lib/Hydra/Plugin.pm at line 39
    [5.139][5.1482:1572](),[5.6015][5.1482:1572]()
    # Called when build $build has started.
    sub buildStarted {
    my ($self, $build) = @_;
    }
    [5.139]
    [5.1572]
    # # Called when build $build has started.
    # sub buildStarted {
    # my ($self, $build) = @_;
    # }
  • replacement in src/lib/Hydra/Plugin.pm at line 44
    [5.1573][5.6078:6304](),[5.6078][5.6078:6304](),[5.6304][5.461:523](),[5.523][5.3495:3497]()
    # 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) = @_;
    }
    [5.1573]
    [5.3497]
    # # 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) = @_;
    # }
  • replacement in src/lib/Hydra/Plugin.pm at line 52
    [5.3498][5.3498:3661](),[5.3661][5.19153:19155](),[5.523][5.19153:19155]()
    # Called when step $step has finished. The build log is stored in the
    # file $logPath (bzip2-compressed).
    sub stepFinished {
    my ($self, $step, $logPath) = @_;
    }
    [5.3498]
    [5.19155]
    # # Called when step $step has finished. The build log is stored in the
    # # file $logPath (bzip2-compressed).
    # sub stepFinished {
    # my ($self, $step, $logPath) = @_;
    # }
  • edit in src/lib/Hydra/TaskDispatcher.pm at line 119
    [4.191]
    [4.191]
    );
    $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."
  • edit in src/lib/Hydra/TaskDispatcher.pm at line 198
    [19.3465]
    [19.3465]
    if (!$task->{"event"}->interested($plugin)) {
    $self->{"prometheus"}->inc("notify_plugin_not_interested", $event_labels);
    return 0;
    }
  • edit in t/Event/BuildFinished.t at line 56
    [15.3369]
    [15.3369]
    subtest "interested" => sub {
    my $event = Hydra::Event::BuildFinished->new(123, []);
    subtest "A plugin which does not implement the API" => sub {
    my $plugin = {};
    my $mock = mock_obj $plugin => ();
    is($event->interestedIn($plugin), 0, "The plugin is not interesting.");
    };
    subtest "A plugin which does implement the API" => sub {
    my $plugin = {};
    my $mock = mock_obj $plugin => (
    add => [
    "buildFinished" => sub {}
    ]
    );
  • edit in t/Event/BuildFinished.t at line 75
    [15.3370]
    [15.3370]
    is($event->interestedIn($plugin), 1, "The plugin is interesting.");
    };
    };
  • edit in t/Event/BuildQueued.t at line 40
    [3.2011]
    [3.2011]
    };
    subtest "interested" => sub {
    my $event = Hydra::Event::BuildQueued->new(123, []);
    subtest "A plugin which does not implement the API" => sub {
    my $plugin = {};
    my $mock = mock_obj $plugin => ();
    is($event->interestedIn($plugin), 0, "The plugin is not interesting.");
    };
    subtest "A plugin which does implement the API" => sub {
    my $plugin = {};
    my $mock = mock_obj $plugin => (
    add => [
    "buildQueued" => sub {}
    ]
    );
    is($event->interestedIn($plugin), 1, "The plugin is interesting.");
    };
  • edit in t/Event/BuildStarted.t at line 46
    [16.1879]
    [16.1879]
    };
    subtest "interested" => sub {
    my $event = Hydra::Event::BuildStarted->new(123, []);
    subtest "A plugin which does not implement the API" => sub {
    my $plugin = {};
    my $mock = mock_obj $plugin => ();
    is($event->interestedIn($plugin), 0, "The plugin is not interesting.");
    };
    subtest "A plugin which does implement the API" => sub {
    my $plugin = {};
    my $mock = mock_obj $plugin => (
    add => [
    "buildStarted" => sub {}
    ]
    );
    is($event->interestedIn($plugin), 1, "The plugin is interesting.");
    };
  • edit in t/Event/StepFinished.t at line 65
    [17.2818]
    [17.2818]
    };
    subtest "interested" => sub {
    my $event = Hydra::Event::StepFinished->new(123, []);
    subtest "A plugin which does not implement the API" => sub {
    my $plugin = {};
    my $mock = mock_obj $plugin => ();
    is($event->interestedIn($plugin), 0, "The plugin is not interesting.");
    };
    subtest "A plugin which does implement the API" => sub {
    my $plugin = {};
    my $mock = mock_obj $plugin => (
    add => [
    "stepFinished" => sub {}
    ]
    );
    is($event->interestedIn($plugin), 1, "The plugin is interesting.");
    };