eval_cached event: change interface to traceID\tjobsetID\tevaluationID

I was not going to break the interface until I noticed
the current implementation uses the string literal \t.
This commit is contained in:
Graham Christensen
2022-02-07 16:13:26 -05:00
parent be531c6c57
commit 2597fa8c11
8 changed files with 206 additions and 5 deletions

View File

@ -7,6 +7,7 @@ use Hydra::Event::BuildQueued;
use Hydra::Event::BuildStarted;
use Hydra::Event::CachedBuildFinished;
use Hydra::Event::CachedBuildQueued;
use Hydra::Event::EvalCached;
use Hydra::Event::EvalStarted;
use Hydra::Event::StepFinished;
@ -16,6 +17,7 @@ my %channels_to_events = (
build_started => \&Hydra::Event::BuildStarted::parse,
cached_build_finished => \&Hydra::Event::CachedBuildFinished::parse,
cached_build_queued => \&Hydra::Event::CachedBuildQueued::parse,
eval_cached => \&Hydra::Event::EvalCached::parse,
eval_started => \&Hydra::Event::EvalStarted::parse,
step_finished => \&Hydra::Event::StepFinished::parse,
);

View File

@ -0,0 +1,63 @@
package Hydra::Event::EvalCached;
use strict;
use warnings;
sub parse :prototype(@) {
unless (@_ == 3) {
die "eval_cached: payload takes exactly three arguments, but ", scalar(@_), " were given";
}
my ($trace_id, $jobset_id, $evaluation_id) = @_;
unless ($jobset_id =~ /^\d+$/) {
die "eval_cached: payload argument jobset_id should be an integer, but '", $jobset_id, "' was given"
}
unless ($evaluation_id =~ /^\d+$/) {
die "eval_cached: payload argument evaluation_id should be an integer, but '", $evaluation_id, "' was given"
}
return Hydra::Event::EvalCached->new($trace_id, int($jobset_id), int($evaluation_id));
}
sub new {
my ($self, $trace_id, $jobset_id, $evaluation_id) = @_;
return bless {
"trace_id" => $trace_id,
"jobset_id" => $jobset_id,
"evaluation_id" => $evaluation_id,
"jobset" => undef,
"evaluation" => undef
}, $self;
}
sub interestedIn {
my ($self, $plugin) = @_;
return int(defined($plugin->can('evalCached')));
}
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";
}
if (!defined($self->{"evaluation"})) {
$self->{"evaluation"} = $db->resultset('JobsetEvals')->find({ id => $self->{"evaluation_id"}})
or die "Jobset $self->{'jobset_id'} does not exist\n";
}
}
sub execute {
my ($self, $db, $plugin) = @_;
$self->load($db);
$plugin->evalCached($self->{"trace_id"}, $self->{"jobset"}, $self->{"evaluation"});
return 1;
}
1;

View File

@ -37,6 +37,11 @@ sub instantiate {
# my ($self, $traceID, $jobset) = @_;
# }
# # Called when an evaluation of $jobset determined the inputs had not changed.
# sub evalCached {
# my ($self, $traceID, $jobset, $evaluation) = @_;
# }
# # Called when build $build has been queued.
# sub buildQueued {
# my ($self, $build) = @_;