hydra-notify: move BuildStarted processing to an Event
[?]
Aug 12, 2021, 1:56 PM
OPSWSU4LKI2F6UJXL7B7MH4C3L7DVVKYW5FARAJ44XYH4WXELLCQCDependencies
- [2]
CQZQE32VImprove handling of Perl's block eval errors - [3]
GQGQEMMAEvent.pm: add a new_event helper to parse and construct an Event - [4]
FN3QFV6Vhydra-notify: Create a helper for running each plugin on an event - [5]
NTEDD7T4Provide a plugin hook for when build steps finish - [6]
IE2PRAQUhydra-queue-runner: Send build notifications - [7]
GE7LFZHQhydra-notify: move buildFinished query in to the function impl - [8]
EKHD4I44Event: init structure and parse existing messages - [9]
FCTX433OAdd buildStarted plugin hook - [10]
P4SME2BCAbstract over postgres' LISTEN/NOTIFY - [11]
4ZCUCACYhydra-notify: Fix processing notifications - [12]
32KJOERMTurn hydra-notify into a daemon - [*]
2JJP7673tests: move to t, allow `yath test` from root
Change contents
- replacement in src/lib/Hydra/Event/BuildStarted.pm at line 22
return bless { "build_id" => $id }, $self;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->buildStarted($self->{"build"});return 1; - edit in src/script/hydra-notify at line 46[4.273]→[4.273:274](∅→∅),[4.274]→[5.1592:1635](∅→∅),[5.1592]→[5.1592:1635](∅→∅),[5.1635]→[5.3412:3413](∅→∅),[5.1657]→[5.3412:3413](∅→∅),[5.3820]→[5.3412:3413](∅→∅),[5.3412]→[5.3412:3413](∅→∅),[5.3413]→[5.1636:1743](∅→∅)
sub buildStarted {my ($buildId) = @_;my $build = $db->resultset('Builds')->find($buildId)or die "build $buildId does not exist\n"; - edit in src/script/hydra-notify at line 47[5.1744]→[5.1744:1780](∅→∅),[5.1780]→[2.699:857](∅→∅),[2.857]→[5.1903:1921](∅→∅),[5.1903]→[5.1903:1921](∅→∅),[5.1921]→[5.3821:3822](∅→∅),[5.1791]→[5.3821:3822](∅→∅)
foreach my $plugin (@plugins) {eval {$plugin->buildStarted($build);1;} or do {print STDERR "error with $plugin->buildStarted: $@\n";}}} - replacement in src/script/hydra-notify at line 123
buildStarted(int($payload[0]));my $event = Hydra::Event::new_event($channelName, $message->{"payload"});runPluginsForEvent($event); - file addition: Event[14.697]
- file addition: BuildStarted.t[0.587]
use strict;use Setup;my %ctx = test_init();require Hydra::Schema;require Hydra::Model::DB;use Hydra::Event;use Hydra::Event::BuildStarted;use Test2::V0;use Test2::Tools::Exception;use Test2::Tools::Mock qw(mock_obj);my $db = Hydra::Model::DB->new;hydra_setup($db);my $project = $db->resultset('Projects')->create({name => "tests", displayname => "", owner => "root"});my $jobset = createBaseJobset("basic", "basic.nix", $ctx{jobsdir});ok(evalSucceeds($jobset), "Evaluating jobs/basic.nix should exit with return code 0");is(nrQueuedBuildsForJobset($jobset), 3, "Evaluating jobs/basic.nix should result in 3 builds");subtest "Parsing build_started" => sub {like(dies { Hydra::Event::parse_payload("build_started", "") },qr/one argument/,"empty payload");like(dies { Hydra::Event::parse_payload("build_started", "abc123\tabc123") },qr/only one argument/,"two arguments");like(dies { Hydra::Event::parse_payload("build_started", "abc123") },qr/should be an integer/,"not an integer");is(Hydra::Event::parse_payload("build_started", "19"),Hydra::Event::BuildStarted->new(19),"Valid parse");};subtest "load" => sub {my $build = $db->resultset('Builds')->search({ },{ limit => 1 })->next;my $event = Hydra::Event::BuildStarted->new($build->id);$event->load($db);is($event->{"build"}->id, $build->id, "The build record matches.");# Create a fake "plugin" with a buildStarted sub, the sub sets this# global passedBuild variable.my $passedBuild;my $plugin = {};my $mock = mock_obj $plugin => (add => ["buildStarted" => sub {my ($self, $build) = @_;$passedBuild = $build;}]);$event->execute($db, $plugin);is($passedBuild->id, $build->id, "The plugin's buildStarted hook is called with the proper build");};done_testing; - edit in t/Event.t at line 4
use Hydra::Event::BuildStarted; - edit in t/Event.t at line 15
subtest "Payload type: build_started" => sub {like(dies { Hydra::Event::parse_payload("build_started", "") },qr/one argument/,"empty payload");like(dies { Hydra::Event::parse_payload("build_started", "abc123\tabc123") },qr/only one argument/,"two arguments"); - edit in t/Event.t at line 16
like(dies { Hydra::Event::parse_payload("build_started", "abc123") },qr/should be an integer/,"not an integer");is(Hydra::Event::parse_payload("build_started", "19"),Hydra::Event::BuildStarted->new(19),"Valid parse");};