Event: init structure and parse existing messages
This commit is contained in:
committed by
Your Name
parent
a14c8ad5f8
commit
64a3e75c10
30
src/lib/Hydra/Event.pm
Normal file
30
src/lib/Hydra/Event.pm
Normal file
@@ -0,0 +1,30 @@
|
||||
package Hydra::Event;
|
||||
|
||||
|
||||
use strict;
|
||||
use Hydra::Event::BuildFinished;
|
||||
use Hydra::Event::BuildStarted;
|
||||
use Hydra::Event::StepFinished;
|
||||
our @ISA = qw(Exporter);
|
||||
our @EXPORT = qw(
|
||||
parse_payload
|
||||
);
|
||||
|
||||
my %channels_to_events = (
|
||||
build_started => \&Hydra::Event::BuildStarted::parse,
|
||||
step_finished => \&Hydra::Event::StepFinished::parse,
|
||||
build_finished => \&Hydra::Event::BuildFinished::parse,
|
||||
);
|
||||
|
||||
|
||||
sub parse_payload :prototype($$) {
|
||||
my ($channel_name, $payload) = @_;
|
||||
my @payload = split /\t/, $payload;
|
||||
|
||||
my $parser = %channels_to_events{$channel_name};
|
||||
unless (defined $parser) {
|
||||
die "Invalid channel name: '$channel_name'";
|
||||
}
|
||||
|
||||
return $parser->(@payload);
|
||||
}
|
Reference in New Issue
Block a user