Redis.pm

filter: Statementstmt 100% 15 / 15 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 100% 19 / 19 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Client/Redis.pm ↑ Summary
1 package Job::Async::Redis;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '0.002';
7  
8 =head1 NAME
9  
10 Job::Async::Redis - L<Net::Async::Redis> backend for L<Job::Async>
11  
12 =head1 SYNOPSIS
13  
14 use IO::Async::Loop;
15 use Job::Async;
16 my $loop = IO::Async::Loop->new;
17 $loop->add( my $jobman = Job::Async->new );
18 my $client = $jobman->client(
19 redis => { uri => 'redis://127.0.0.1', }
20 );
21 my $worker = $jobman->worker(
22 redis => { uri => 'redis://127.0.0.1', }
23 );
24 Future->needs_all(
25 $client->start,
26 )->get;
27  
28 $worker->jobs->each(sub {
29 $_->done('' . reverse $_->data('some_data'))
30 });
31 print Future->needs_all(
32 $client->start,
33 $worker->trigger
34 )->then(sub {
35 $client->submit(
36 some_data => 'reverse me please'
37 )->future
38 })->get;
39  
40 =head1 DESCRIPTION
41  
42 The system can be configured to select a performance/reliability tradeoff
43 as follows. Please note that clients and workers B<must> be configured to
44 use the same mode - results are undefined if you try to mix clients and
45 workers using different modes. If it works, don't rely on it.
46  
47 =head2 Operational modes
48  
49 =head3 simple
50  
51 Jobs are submitted by serialising as JSON and pushing to a Redis list
52 as a queue.
53  
54 Workers retrieve jobs from queue, and send the results via pubsub.
55  
56 Multiple queues can be used for priority handling - the client can route
57 based on the job data.
58  
59 =head3 recoverable
60  
61 As with simple mode, queues are used for communication between the
62 clients and workers. However, these queues contain only the job ID.
63  
64 Actual job data is stored in a hash key, and once the worker completes
65 the result is also stored here.
66  
67 Job completion will trigger a L<Net::Redis::Async::Commands/publish>
68 notification, allowing clients to listen for completion.
69  
70 Multiple queues can be used, as with C<simple> mode.
71  
72 =head3 reliable
73  
74 Each worker uses L<Net::Async::Redis::Commands/brpoplpush> to await job IDs
75 posted to a single queue.
76  
77 Job details are stored in a hash key, as with the C<recoverable> approach.
78  
79 When a worker starts on a job, the ID is atomically moved to an in-process queue,
80 and this is used to track whether workers are still valid.
81  
82 Only one queue is allowed per worker, due to limitations of the
83 L<Net::Async::Redis::Commands/brpoplpush> implementation as described in
84 L<this issue|https://github.com/antirez/redis/issues/1785>.
85  
86 =cut
87  
88 1 ▶use Job::Async::Worker::Redis;
Subroutine BEGIN: called CC=1 SCAR=0.0
89 1 ▶use Job::Async::Client::Redis;
Subroutine BEGIN: called CC=1 SCAR=0.0
90  
91 1 our %MODES = (
92 simple => 1,
93 recoverable => 1,
94 reliable => 1
95 );
96  
97 1 1;
98  
99 =head1 AUTHOR
100  
101 Tom Molesworth <TEAM@cpan.org>
102  
103 =head1 LICENSE
104  
105 Copyright Tom Molesworth 2016-2019. Licensed under the same terms as Perl itself.
106  
« Client/Redis.pm ↑ Summary