App-MultiModule-Tasks-DocGateway
view release on metacpan or search on metacpan
lib/App/MultiModule/Tasks/DocGateway.pm view on Meta::CPAN
}
}
sub _insert {
my $self = shift;
my $message = shift;
eval {
local $SIG{ALRM} = sub { die "timed out\n"; };
my $timeout = $self->{config}->{pg_insert_timeout} || 2;
alarm $timeout;
my $c = $self->_get_connection();
my $insert = Storable::dclone($message);
delete $insert->{'.ipc_transit_meta'};
$c->mongo_do(
$message->{document_database},
$message->{document_collection},
'insert',
$insert);
};
alarm 0;
if($@) {
$self->error("App::MultiModule::Tasks::DocGateway::_insert failed: $@");
return;
}
}
sub _find {
my $self = shift;
my $message = shift;
#TODO: validate $message->{document_filter} here
#TODO: variant that emits once per return document
my @emits = eval {
local $SIG{ALRM} = sub { die "timed out\n"; };
my $timeout = $self->{config}->{pg_find_timeout} || 7;
alarm $timeout;
my $c = $self->_get_connection();
my $documents = $c->mongo_find(
$message->{document_database},
$message->{document_collection},
$message->{document_filter},
);
$message->{document_returns} = $documents;
return ($message);
};
alarm 0;
if($@) {
$self->error("App::MultiModule::Tasks::DocGateway::_find failed: $@");
return;
}
$self->emit($_) for @emits;
}
sub _get_connection {
my $self = shift;
my $handle = eval {
local $SIG{ALRM} = sub { die "timed out\n"; };
my $timeout = $self->{config}->{pg_connect_timeout} || 5;
alarm $timeout;
return Postgres::Mongo->new(
userid => $self->{pg_userid},
password => $self->{pg_password},
);
};
alarm 0;
$self->error("App::MultiModule::Tasks::DocGateway::_get_connection failed: $@") if $@;
return $handle;
}
=head2 set_config
=cut
sub set_config {
my $self = shift;
my $config = shift;
$self->{config} = $config;
my $state = $self->{state};
$self->{pg_userid} = $config->{pg_userid} || 'testuser1';
$self->{pg_password} = $config->{pg_password} || 'testuser1';
}
=head2 is_stateful
=cut
sub is_stateful {
return 'absolultely';
}
=head1 AUTHOR
Dana M. Diederich, C<< <dana@realms.org> >>
=head1 BUGS
Please report any bugs or feature requests through L<https://github.com/dana/perl-App-MultiModule-Tasks-DocGateway/issues>. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc App::MultiModule::Tasks::DocGateway
You can also look for information at:
=over 4
=item * Report bugs here:
L<https://github.com/dana/perl-App-MultiModule-Tasks-DocGateway/issues>
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/App-MultiModule-Tasks-DocGateway>
=item * CPAN Ratings
L<http://cpanratings.perl.org/d/App-MultiModule-Tasks-DocGateway>
=item * Search CPAN
L<https://metacpan.org/module/App::MultiModule::Tasks::DocGateway>
=back
=head1 ACKNOWLEDGEMENTS
=head1 LICENSE AND COPYRIGHT
Copyright 2016 Dana M. Diederich.
This program is free software; you can redistribute it and/or modify it
under the terms of the the Artistic License (2.0). You may obtain a
copy of the full license at:
L<http://www.perlfoundation.org/artistic_license_2_0>
( run in 0.772 second using v1.01-cache-2.11-cpan-9581c071862 )