eval_started event: change interface to traceID\tjobsetID
I was not going to break the interface until I noticed the current implementation uses the string literal \t.
This commit is contained in:
parent
3864ca820a
commit
c30f084f32
|
@ -57,7 +57,7 @@ It is possible for subsequent deliveries of the same `build_finished` data to im
|
||||||
|
|
||||||
### `eval_started`
|
### `eval_started`
|
||||||
|
|
||||||
* **Payload:** Exactly three values, separated by the two-character string `\t` (ie: not a tab): an opaque trace ID representing this evaluation, the name of the project, and the name of the jobset.
|
* **Payload:** Exactly two values, tab separated: an opaque trace ID representing this evaluation, and the ID of the jobset.
|
||||||
* **When:** At the beginning of the evaluation phase for the jobset, before any work is done.
|
* **When:** At the beginning of the evaluation phase for the jobset, before any work is done.
|
||||||
* **Delivery Semantics:** Ephemeral. `hydra-notify` must be running to react to this event. No record of this event is stored.
|
* **Delivery Semantics:** Ephemeral. `hydra-notify` must be running to react to this event. No record of this event is stored.
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ use Hydra::Event::BuildQueued;
|
||||||
use Hydra::Event::BuildStarted;
|
use Hydra::Event::BuildStarted;
|
||||||
use Hydra::Event::CachedBuildFinished;
|
use Hydra::Event::CachedBuildFinished;
|
||||||
use Hydra::Event::CachedBuildQueued;
|
use Hydra::Event::CachedBuildQueued;
|
||||||
|
use Hydra::Event::EvalStarted;
|
||||||
use Hydra::Event::StepFinished;
|
use Hydra::Event::StepFinished;
|
||||||
|
|
||||||
my %channels_to_events = (
|
my %channels_to_events = (
|
||||||
|
@ -15,6 +16,7 @@ my %channels_to_events = (
|
||||||
build_started => \&Hydra::Event::BuildStarted::parse,
|
build_started => \&Hydra::Event::BuildStarted::parse,
|
||||||
cached_build_finished => \&Hydra::Event::CachedBuildFinished::parse,
|
cached_build_finished => \&Hydra::Event::CachedBuildFinished::parse,
|
||||||
cached_build_queued => \&Hydra::Event::CachedBuildQueued::parse,
|
cached_build_queued => \&Hydra::Event::CachedBuildQueued::parse,
|
||||||
|
eval_started => \&Hydra::Event::EvalStarted::parse,
|
||||||
step_finished => \&Hydra::Event::StepFinished::parse,
|
step_finished => \&Hydra::Event::StepFinished::parse,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
53
src/lib/Hydra/Event/EvalStarted.pm
Normal file
53
src/lib/Hydra/Event/EvalStarted.pm
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
package Hydra::Event::EvalStarted;
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
sub parse :prototype(@) {
|
||||||
|
unless (@_ == 2) {
|
||||||
|
die "eval_started: payload takes two arguments, but ", scalar(@_), " were given";
|
||||||
|
}
|
||||||
|
|
||||||
|
my ($trace_id, $jobset_id) = @_;
|
||||||
|
|
||||||
|
unless ($jobset_id =~ /^\d+$/) {
|
||||||
|
die "eval_started: payload argument should be an integer, but '", $jobset_id, "' was given"
|
||||||
|
}
|
||||||
|
|
||||||
|
return Hydra::Event::EvalStarted->new($trace_id, int($jobset_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
sub new {
|
||||||
|
my ($self, $trace_id, $jobset_id) = @_;
|
||||||
|
return bless {
|
||||||
|
"trace_id" => $trace_id,
|
||||||
|
"jobset_id" => $jobset_id,
|
||||||
|
"jobset" => undef
|
||||||
|
}, $self;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub interestedIn {
|
||||||
|
my ($self, $plugin) = @_;
|
||||||
|
return int(defined($plugin->can('evalStarted')));
|
||||||
|
}
|
||||||
|
|
||||||
|
sub load {
|
||||||
|
my ($self, $db) = @_;
|
||||||
|
|
||||||
|
if (!defined($self->{"jobset"})) {
|
||||||
|
$self->{"jobset"} = $db->resultset('Jobsets')->find({ id => $self->{"jobset_id"}})
|
||||||
|
or die "Jobset $self->{'jobset_id'} does not exist\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub execute {
|
||||||
|
my ($self, $db, $plugin) = @_;
|
||||||
|
|
||||||
|
$self->load($db);
|
||||||
|
|
||||||
|
$plugin->evalStarted($self->{"trace_id"}, $self->{"jobset"});
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
|
@ -31,6 +31,12 @@ sub instantiate {
|
||||||
# See the tests in t/Event/*.t for arguments, and the documentation for
|
# See the tests in t/Event/*.t for arguments, and the documentation for
|
||||||
# notify events for semantics.
|
# notify events for semantics.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
# # Called when an evaluation of $jobset has begun.
|
||||||
|
# sub evalStarted {
|
||||||
|
# my ($self, $traceID, $jobset) = @_;
|
||||||
|
# }
|
||||||
|
|
||||||
# # Called when build $build has been queued.
|
# # Called when build $build has been queued.
|
||||||
# sub buildQueued {
|
# sub buildQueued {
|
||||||
# my ($self, $build) = @_;
|
# my ($self, $build) = @_;
|
||||||
|
|
|
@ -861,7 +861,7 @@ sub checkJobset {
|
||||||
my $tmpId = "${startTime}.$$";
|
my $tmpId = "${startTime}.$$";
|
||||||
|
|
||||||
$db->storage->dbh->do("notify eval_started, ?", undef,
|
$db->storage->dbh->do("notify eval_started, ?", undef,
|
||||||
join('\t', $tmpId, $jobset->get_column('project'), $jobset->name));
|
join("\t", $tmpId, $jobset->get_column('id')));
|
||||||
|
|
||||||
eval {
|
eval {
|
||||||
checkJobsetWrapped($jobset, $tmpId);
|
checkJobsetWrapped($jobset, $tmpId);
|
||||||
|
|
|
@ -98,6 +98,7 @@ $listener->subscribe("build_queued");
|
||||||
$listener->subscribe("build_started");
|
$listener->subscribe("build_started");
|
||||||
$listener->subscribe("cached_build_finished");
|
$listener->subscribe("cached_build_finished");
|
||||||
$listener->subscribe("cached_build_queued");
|
$listener->subscribe("cached_build_queued");
|
||||||
|
$listener->subscribe("eval_started");
|
||||||
$listener->subscribe("hydra_notify_dump_metrics");
|
$listener->subscribe("hydra_notify_dump_metrics");
|
||||||
$listener->subscribe("step_finished");
|
$listener->subscribe("step_finished");
|
||||||
|
|
||||||
|
|
94
t/Hydra/Event/EvalStarted.t
Normal file
94
t/Hydra/Event/EvalStarted.t
Normal file
|
@ -0,0 +1,94 @@
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use Setup;
|
||||||
|
use Hydra::Event;
|
||||||
|
use Hydra::Event::EvalStarted;
|
||||||
|
use Test2::V0;
|
||||||
|
use Test2::Tools::Exception;
|
||||||
|
use Test2::Tools::Mock qw(mock_obj);
|
||||||
|
|
||||||
|
my $ctx = test_context();
|
||||||
|
|
||||||
|
my $builds = $ctx->makeAndEvaluateJobset(
|
||||||
|
expression => "basic.nix",
|
||||||
|
build => 1
|
||||||
|
);
|
||||||
|
|
||||||
|
subtest "Parsing eval_started" => sub {
|
||||||
|
like(
|
||||||
|
dies { Hydra::Event::parse_payload("eval_started", "") },
|
||||||
|
qr/two arguments/,
|
||||||
|
"empty payload"
|
||||||
|
);
|
||||||
|
like(
|
||||||
|
dies { Hydra::Event::parse_payload("eval_started", "abc123") },
|
||||||
|
qr/two arguments/,
|
||||||
|
"one argument"
|
||||||
|
);
|
||||||
|
like(
|
||||||
|
dies { Hydra::Event::parse_payload("eval_started", "abc123\tabc123\tabc123") },
|
||||||
|
qr/two arguments/,
|
||||||
|
"three arguments"
|
||||||
|
);
|
||||||
|
like(
|
||||||
|
dies { Hydra::Event::parse_payload("eval_started", "abc123\tabc123") },
|
||||||
|
qr/should be an integer/,
|
||||||
|
"not an integer: second argument"
|
||||||
|
);
|
||||||
|
is(
|
||||||
|
Hydra::Event::parse_payload("eval_started", "abc123\t456"),
|
||||||
|
Hydra::Event::EvalStarted->new("abc123", 456)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
subtest "interested" => sub {
|
||||||
|
my $event = Hydra::Event::EvalStarted->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 => [
|
||||||
|
"evalStarted" => sub {}
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
is($event->interestedIn($plugin), 1, "The plugin is interesting.");
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
subtest "load" => sub {
|
||||||
|
my $jobset = $builds->{"empty_dir"}->jobset;
|
||||||
|
|
||||||
|
my $event = Hydra::Event::EvalStarted->new("traceID", $jobset->id);
|
||||||
|
|
||||||
|
$event->load($ctx->db());
|
||||||
|
is($event->{"jobset"}->get_column("id"), $jobset->id, "The jobset record matches.");
|
||||||
|
|
||||||
|
# Create a fake "plugin" with a evalStarted sub, the sub sets this
|
||||||
|
# "global" passedTraceID, passedJobset
|
||||||
|
my $passedTraceID;
|
||||||
|
my $passedJobset;
|
||||||
|
my $plugin = {};
|
||||||
|
my $mock = mock_obj $plugin => (
|
||||||
|
add => [
|
||||||
|
"evalStarted" => sub {
|
||||||
|
my ($self, $traceID, $jobset) = @_;
|
||||||
|
$passedTraceID = $traceID;
|
||||||
|
$passedJobset = $jobset;
|
||||||
|
}
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$event->execute($ctx->db(), $plugin);
|
||||||
|
is($passedTraceID, "traceID", "The plugin is told what the trace ID was");
|
||||||
|
is($passedJobset->get_column("id"), $jobset->id, "The plugin's evalStarted hook is called with the right jobset");
|
||||||
|
};
|
||||||
|
|
||||||
|
done_testing;
|
|
@ -36,9 +36,18 @@ my $builds = $ctx->makeAndEvaluateJobset(
|
||||||
jobsdir => $jobsetdir,
|
jobsdir => $jobsetdir,
|
||||||
build => 0
|
build => 0
|
||||||
);
|
);
|
||||||
|
my $jobset = $builds->{"stable-job-queued"}->jobset;
|
||||||
|
|
||||||
|
my $traceID;
|
||||||
|
|
||||||
subtest "on the initial evaluation" => sub {
|
subtest "on the initial evaluation" => sub {
|
||||||
is($listener->block_for_messages(0)->()->{"channel"}, "eval_started", "every eval starts with a notification");
|
my $startedMsg = $listener->block_for_messages(0)->();
|
||||||
|
is($startedMsg->{"channel"}, "eval_started", "every eval starts with a notification");
|
||||||
|
|
||||||
|
my ($traceID, $jobsetID) = split("\t", $startedMsg->{"payload"});
|
||||||
|
isnt($traceID, "", "we got a trace id");
|
||||||
|
is($jobsetID, $jobset->get_column('id'), "the jobset ID matches");
|
||||||
|
|
||||||
is($listener->block_for_messages(0)->()->{"channel"}, "build_queued", "expect 1/4 builds being queued");
|
is($listener->block_for_messages(0)->()->{"channel"}, "build_queued", "expect 1/4 builds being queued");
|
||||||
is($listener->block_for_messages(0)->()->{"channel"}, "build_queued", "expect 2/4 builds being queued");
|
is($listener->block_for_messages(0)->()->{"channel"}, "build_queued", "expect 2/4 builds being queued");
|
||||||
is($listener->block_for_messages(0)->()->{"channel"}, "build_queued", "expect 3/4 builds being queued");
|
is($listener->block_for_messages(0)->()->{"channel"}, "build_queued", "expect 3/4 builds being queued");
|
||||||
|
|
Loading…
Reference in a new issue