Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: bobtfish/Message-Passing-Output-MongoDB
base: ac280ee848
...
head fork: bobtfish/Message-Passing-Output-MongoDB
compare: 1eb79aaf92
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 27 additions and 23 deletions.
  1. +4 −0 Makefile.PL
  2. +23 −23 lib/Message/Passing/Output/MongoDB.pm
View
4 Makefile.PL
@@ -12,6 +12,10 @@ requires 'Message::Passing' => '0.009';
requires 'MongoDB';
requires 'Moose';
requires 'MooseX::Types';
+requires 'AnyEvent';
+requires 'MooseX::Types::ISO8601';
+requires 'aliased';
+requires 'namespace::autoclean';
test_requires 'Try::Tiny';
author_requires(
View
46 lib/Message/Passing/Output/MongoDB.pm
@@ -8,7 +8,6 @@ use AnyEvent;
use Scalar::Util qw/ weaken /;
use MooseX::Types::Moose qw/ ArrayRef HashRef Str Bool Int Num /;
use Moose::Util::TypeConstraints;
-use Try::Tiny qw/ try catch /;
use aliased 'DateTime' => 'DT';
use MooseX::Types::ISO8601 qw/ ISO8601DateTimeStr /;
use Data::Dumper;
@@ -69,14 +68,14 @@ has _collection => (
isa => 'MongoDB::Collection',
lazy => 1,
builder => '_build_logs_collection',
-);
+);
sub _build_logs_collection {
my ($self) = @_;
my $collection_name = $self->collection;
my $collection = $self->_db->$collection_name;
-
- if (defined $self->indexes) {
+
+ if ($self->_has_indexes) {
foreach my $index (@{$self->indexes}){
$collection->ensure_index(@$index);
warn("ensure index " . Dumper($index)) if $self->verbose;
@@ -120,6 +119,7 @@ sub consume {
has indexes => (
isa => ArrayRef[ArrayRef[HashRef]],
is => 'ro',
+ predicate => '_has_indexes',
);
has retention => (
@@ -131,31 +131,31 @@ has retention => (
has _cleaner => (
is => 'ro',
- isa => 'Undef|ArrayRef',
lazy => 1,
builder => '_build_cleaner'
);
sub _build_cleaner {
- my $self = shift;
- weaken($self);
- return if $self->retention == 0;
- my $time = 60 * 60 * 24; # Every day
- my $retention_date = DT->from_epoch(epoch => time() - $self->retention );
- AnyEvent->timer(
- after => 100,
- interval => $time,
- cb => sub {
- my $result = $self->_collection->remove(
- { date => { '$lt' => to_ISO8601DateTimeStr($retention_date) } } );
- warn("Cleaned old log failure\n") if !$result;
- warn("Cleaned old log \n") if $self->verbose;
- },
- );
- }
+ my $self = shift;
+ weaken($self);
+ my $time = 60 * 60 * 24; # Every day
+ my $retention_date = DT->from_epoch(epoch => time() - $self->retention );
+ AnyEvent->timer(
+ after => 100,
+ interval => $time,
+ cb => sub {
+ my $result = $self->_collection->remove(
+ { date => { '$lt' => to_ISO8601DateTimeStr($retention_date) } } );
+ warn("Cleaned old log failure\n") if !$result;
+ warn("Cleaned old log \n") if $self->verbose;
+ },
+ );
+}
-sub BUILD{
- shift->_cleaner;
+sub BUILD {
+ my ($self) = @_;
+ $self->_cleaner
+ if $self->retention != 0;
}
1;

No commit comments for this range

Something went wrong with that request. Please try again.