App-HistHub
view release on metacpan or search on metacpan
lib/App/HistHub/Schema/HistQueue.pm view on Meta::CPAN
"timestamp",
{ data_type => "INTEGER", is_nullable => 0, size => undef },
);
__PACKAGE__->set_primary_key("id");
package App::HistHub::Schema::HistQueue;
use strict;
use warnings;
use DateTime;
__PACKAGE__->belongs_to( peer => 'App::HistHub::Schema::Peer' );
__PACKAGE__->inflate_column(
timestamp => {
inflate => sub { DateTime->from_epoch( epoch => shift ) },
deflate => sub { shift->epoch },
},
);
sub insert {
my $self = shift;
$self->timestamp( DateTime->now ) unless $self->timestamp;
$self->next::method(@_);
}
1;
lib/App/HistHub/Schema/Peer.pm view on Meta::CPAN
"access_time",
{ data_type => "INTEGER", is_nullable => 0, size => undef },
);
__PACKAGE__->set_primary_key("id");
package App::HistHub::Schema::Peer;
use strict;
use warnings;
use DateTime;
use Data::UUID;
use Digest::SHA1 qw/sha1_hex/;
__PACKAGE__->has_many( queue => 'App::HistHub::Schema::HistQueue', 'peer', { order_by => 'timestamp' } );
__PACKAGE__->inflate_column(
access_time => {
inflate => sub { DateTime->from_epoch( epoch => shift ) },
deflate => sub { shift->epoch },
},
);
sub insert {
my $self = shift;
$self->uid( sha1_hex( Data::UUID->new->create ) );
$self->access_time( DateTime->now ) unless $self->access_time;
$self->next::method(@_);
}
sub push_queue {
my ($self, $cmd) = @_;
$self->add_to_queue({ data => $cmd });
}
sub pop_queue {
my $self = shift;
( run in 0.394 second using v1.01-cache-2.11-cpan-05444aca049 )