Minion/Notifier/Transport/Pg.pm untested

filter: Statementstmt 0.0% 0 / 23 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 32 CC 1 SCAR 6.9
CC
1
Cov
0%
listen
2.0
send
2.0
_start
2.0
CRAP 2.0
1 package Minion::Notifier::Transport::Pg;
2  
3 use Mojo::Base 'Minion::Notifier::Transport';
4  
5 use Mojo::Pg;
6 use Mojo::JSON;
7  
8 has pg => sub { die 'A Mojo::Pg instance is required' };
9  
10 has channel => 'minion_notifier_job';
11  
12 sub listen {
13 my $self = shift;
14 $self->pg->pubsub->listen($self->channel => sub {
15 my ($pubsub, $payload) = @_;
16 my $args = Mojo::JSON::decode_json $payload;
17 $self->emit(notified => @$args);
18 });
19 }
20  
21 sub send {
22 my ($self, $id, $message) = @_;
23 $self->pg->pubsub->notify(
24 $self->channel,
25 Mojo::JSON::encode_json([$id, $message]),
26 );
27 }
28  
29 sub _start {
30 my $self = shift;
31 # The pubsub object needs to be refreshed or else we'll get
32 # zombies pretty quickly
33 $self->pg->pubsub->reset;
34 }
35  
36 1;
37