Event: init structure and parse existing messages

This commit is contained in:
Graham Christensen
2021-04-05 19:29:45 +00:00
committed by Your Name
parent a14c8ad5f8
commit 64a3e75c10
5 changed files with 222 additions and 0 deletions

View File

@ -0,0 +1,25 @@
package Hydra::Event::BuildFinished;
use strict;
use warnings;
sub parse :prototype(@) {
if (@_ == 0) {
die "build_finished: payload takes at least one argument, but ", scalar(@_), " were given";
}
my @failures = grep(!/^\d+$/, @_);
if (@failures > 0) {
die "build_finished: payload arguments should be integers, but we received the following non-integers:", @failures;
}
my ($build_id, @dependents) = map int, @_;
return Hydra::Event::BuildFinished->new($build_id, \@dependents);
}
sub new {
my ($self, $build_id, $dependencies) = @_;
return bless { "build_id" => $build_id, "dependencies" => $dependencies }, $self;
}
1;

View File

@ -0,0 +1,25 @@
package Hydra::Event::BuildStarted;
use strict;
use warnings;
sub parse :prototype(@) {
unless (@_ == 1) {
die "build_started: payload takes only one argument, but ", scalar(@_), " were given";
}
my ($build_id) = @_;
unless ($build_id =~ /^\d+$/) {
die "build_started: payload argument should be an integer, but '", $build_id, "' was given"
}
return Hydra::Event::BuildStarted->new(int($build_id));
}
sub new {
my ($self, $id) = @_;
return bless { "build_id" => $id }, $self;
}
1;

View File

@ -0,0 +1,29 @@
package Hydra::Event::StepFinished;
use strict;
use warnings;
sub parse :prototype(@) {
unless (@_ == 3) {
die "step_finished: payload takes exactly three arguments, but ", scalar(@_), " were given";
}
my ($build_id, $step_number, $log_path) = @_;
unless ($build_id =~ /^\d+$/) {
die "step_finished: payload argument build_id should be an integer, but '", $build_id, "' was given"
}
unless ($step_number =~ /^\d+$/) {
die "step_finished: payload argument step_number should be an integer, but '", $step_number, "' was given"
}
return Hydra::Event::StepFinished->new(int($build_id), int($step_number), $log_path);
}
sub new :prototype($$$) {
my ($self, $build_id, $step_number, $log_path) = @_;
return bless { "build_id" => $build_id, "step_number" => $step_number, "log_path" => $log_path }, $self;
}
1;