RunCommandLogs: set a UUID automatically
This commit is contained in:
parent
89e8676d80
commit
dcb0c1425c
|
@ -174,9 +174,30 @@ __PACKAGE__->belongs_to(
|
||||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ZVpYU6k3d/k/nitjpdgf/A
|
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ZVpYU6k3d/k/nitjpdgf/A
|
||||||
|
|
||||||
use POSIX qw(WEXITSTATUS WIFEXITED WIFSIGNALED WTERMSIG);
|
use POSIX qw(WEXITSTATUS WIFEXITED WIFSIGNALED WTERMSIG);
|
||||||
|
use UUID4::Tiny qw(create_uuid_string);
|
||||||
use Digest::SHA1 qw(sha1_hex);
|
use Digest::SHA1 qw(sha1_hex);
|
||||||
use Hydra::Model::DB;
|
use Hydra::Model::DB;
|
||||||
|
|
||||||
|
|
||||||
|
=head2 new
|
||||||
|
|
||||||
|
Initialize a new row object.
|
||||||
|
|
||||||
|
Sets the UUID automatically unless a UUID is specified in the attributes.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
sub new {
|
||||||
|
my ($class, $attrs) = @_;
|
||||||
|
|
||||||
|
if (!defined $attrs->{uuid}) {
|
||||||
|
$attrs->{uuid} = create_uuid_string();
|
||||||
|
}
|
||||||
|
|
||||||
|
my $new = $class->next::method($attrs);
|
||||||
|
|
||||||
|
return $new;
|
||||||
|
}
|
||||||
|
|
||||||
=head2 started
|
=head2 started
|
||||||
|
|
||||||
Update the row with the current timestamp as the start time.
|
Update the row with the current timestamp as the start time.
|
||||||
|
|
|
@ -20,6 +20,12 @@ sub new_run_log {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
subtest "A new record has a UUID" => sub {
|
||||||
|
my $runlog = new_run_log();
|
||||||
|
is(length($runlog->uuid), 36, "The UUID attribute is sufficiently UUID-like.");
|
||||||
|
like($runlog->uuid, qr/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/, "The UUID attribute is sufficiently UUID-like.");
|
||||||
|
};
|
||||||
|
|
||||||
subtest "Not yet started" => sub {
|
subtest "Not yet started" => sub {
|
||||||
my $runlog = new_run_log();
|
my $runlog = new_run_log();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue