Minion/Notifier/Transport/Redis.pm untested

filter: Statementstmt 0.0% 0 / 29 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 38 CC 2 SCAR 12.0
CC
2
Cov
0%
listen
6.0
send
2.0
BEGIN
2.0
CRAP 3.3
1 package Minion::Notifier::Transport::Redis;
2  
3 use Mojo::Base 'Minion::Notifier::Transport';
4  
5 use Mojo::Redis2;
6 use Mojo::JSON;
7  
8 has redis => sub { die 'A Mojo::Redis2 instance is required' };
9  
10 has channel => 'minion_notifier_job';
11  
12 sub listen {
13 my $self = shift;
14 my $channel = $self->channel;
15 $self->redis->on(message => sub {
16 my ($redis, $payload, $c) = @_;
17 return unless $c eq $channel;
18 my $args = Mojo::JSON::decode_json $payload;
19 $self->emit(notified => @$args);
20 });
21 $self->redis->subscribe([$channel], sub {});
22 }
23  
24 sub send {
25 my ($self, $id, $message) = @_;
26 my $payload = Mojo::JSON::encode_json([$id, $message]);
27 Mojo::IOLoop->delay(sub{
28 $self->redis->publish($self->channel, $payload, shift->begin);
29 })->wait;
30 }
31  
32 1;
33