hydra-notify: listen for build_queued events
[?]
Dec 20, 2021, 6:18 PM
LM2LEJNHWOJKU7UKU3CZU2ZHZGF25LJG4IFKQLTH2DH4VEMEVVZQCDependencies
- [2]
OPSWSU4Lhydra-notify: move BuildStarted processing to an Event - [*]
EKHD4I44Event: init structure and parse existing messages - [*]
IE2PRAQUhydra-queue-runner: Send build notifications - [*]
P4SME2BCAbstract over postgres' LISTEN/NOTIFY
Change contents
- file addition: BuildQueued.pm[4.1]
package Hydra::Event::BuildQueued;use strict;use warnings;sub parse :prototype(@) {unless (@_ == 1) {die "build_queued: payload takes only one argument, but ", scalar(@_), " were given";}my ($build_id) = @_;unless ($build_id =~ /^\d+$/) {die "build_queued: payload argument should be an integer, but '", $build_id, "' was given"}return Hydra::Event::BuildQueued->new(int($build_id));}sub new {my ($self, $id) = @_;return bless {"build_id" => $id,"build" => undef}, $self;}sub load {my ($self, $db) = @_;if (!defined($self->{"build"})) {$self->{"build"} = $db->resultset('Builds')->find($self->{"build_id"})or die "build $self->{'build_id'} does not exist\n";}}sub execute {my ($self, $db, $plugin) = @_;$self->load($db);$plugin->buildQueued($self->{"build"});return 1;}1; - edit in src/lib/Hydra/Event.pm at line 6
use Hydra::Event::BuildQueued; - edit in src/lib/Hydra/Event.pm at line 11
build_queued => \&Hydra::Event::BuildQueued::parse, - edit in src/script/hydra-notify at line 96[6.1804][6.1804]
$listener->subscribe("build_queued"); - file addition: BuildQueued.t[2.587]
use strict;use warnings;use Setup;use Hydra::Event;use Hydra::Event::BuildQueued;use Test2::V0;use Test2::Tools::Exception;use Test2::Tools::Mock qw(mock_obj);my $ctx = test_context();my $db = $ctx->db();my $builds = $ctx->makeAndEvaluateJobset(expression => "basic.nix");subtest "Parsing build_queued" => sub {like(dies { Hydra::Event::parse_payload("build_queued", "") },qr/one argument/,"empty payload");like(dies { Hydra::Event::parse_payload("build_queued", "abc123\tabc123") },qr/only one argument/,"two arguments");like(dies { Hydra::Event::parse_payload("build_queued", "abc123") },qr/should be an integer/,"not an integer");is(Hydra::Event::parse_payload("build_queued", "19"),Hydra::Event::BuildQueued->new(19),"Valid parse");};subtest "load" => sub {my $build = $builds->{"empty_dir"};my $event = Hydra::Event::BuildQueued->new($build->id);$event->load($db);is($event->{"build"}->id, $build->id, "The build record matches.");# Create a fake "plugin" with a buildQueued sub, the sub sets this# global passedBuild variable.my $passedBuild;my $plugin = {};my $mock = mock_obj $plugin => (add => ["buildQueued" => sub {my ($self, $build) = @_;$passedBuild = $build;}]);$event->execute($db, $plugin);is($passedBuild->id, $build->id, "The plugin's buildQueued hook is called with the proper build");};done_testing;