line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SQS::Consumers::DeleteAndFork; |
2
|
8
|
|
|
8
|
|
47
|
use Moose; |
|
8
|
|
|
|
|
20
|
|
|
8
|
|
|
|
|
42
|
|
3
|
8
|
|
|
8
|
|
46537
|
use namespace::autoclean; |
|
8
|
|
|
|
|
21
|
|
|
8
|
|
|
|
|
57
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
sub fetch_message { |
6
|
5
|
|
|
5
|
0
|
21
|
my $self = shift; |
7
|
5
|
|
|
|
|
16
|
my $worker = shift; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# Automatically reap child processes so we don't get zombies |
10
|
5
|
|
|
|
|
120
|
$SIG{ CHLD } = 'IGNORE'; |
11
|
|
|
|
|
|
|
|
12
|
5
|
|
|
|
|
134
|
$worker->log->debug('Receiving Messages'); |
13
|
5
|
|
|
|
|
218
|
my $message_pack = $worker->receive_message(); |
14
|
|
|
|
|
|
|
|
15
|
5
|
|
|
|
|
119
|
$worker->log->debug(sprintf "Got %d messages", scalar(@{ $message_pack->Messages })); |
|
5
|
|
|
|
|
20
|
|
16
|
|
|
|
|
|
|
|
17
|
5
|
|
|
|
|
449
|
foreach my $message (@{$message_pack->Messages}) { |
|
5
|
|
|
|
|
18
|
|
18
|
5
|
|
|
|
|
268
|
$worker->log->info("Processing message " . $message->ReceiptHandle); |
19
|
|
|
|
|
|
|
# We have to delete the message from the queue in any case, but we don't |
20
|
|
|
|
|
|
|
# want to wait for the process to finish (if the process is longer than |
21
|
|
|
|
|
|
|
# the messages visibility timeout, then the message will possibly be redelivered |
22
|
5
|
|
|
|
|
216
|
$worker->delete_message($message); |
23
|
|
|
|
|
|
|
|
24
|
5
|
|
|
|
|
5626
|
my $chld = fork; |
25
|
5
|
50
|
|
|
|
376
|
if ($chld == -1) { |
|
|
100
|
|
|
|
|
|
26
|
0
|
|
|
|
|
0
|
$worker->log->error("problem forking: ", $!); |
27
|
|
|
|
|
|
|
} elsif ($chld == 0) { |
28
|
|
|
|
|
|
|
# Restore SIG_CHLD in the child process to the default Perl behaviour (so |
29
|
|
|
|
|
|
|
# system, f.ex, will be able to correctly collect exit codes) |
30
|
2
|
|
|
|
|
136
|
$SIG{ CHLD } = 'DEFAULT'; |
31
|
|
|
|
|
|
|
|
32
|
2
|
|
|
|
|
31
|
eval { |
33
|
2
|
|
|
|
|
70
|
$worker->process_message($message); |
34
|
|
|
|
|
|
|
}; |
35
|
2
|
100
|
|
|
|
343
|
if ($@) { |
36
|
1
|
|
|
|
|
229
|
$worker->log->error("Exception caught: " . $@); |
37
|
1
|
|
|
|
|
117
|
$worker->on_failure->($worker, $message); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
# Exit the child (nothing more to do in childs) |
40
|
2
|
|
|
|
|
334
|
exit; |
41
|
|
|
|
|
|
|
} else { |
42
|
|
|
|
|
|
|
# Nothing special to do in the parent. Just keep on processing messages |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
48
|
|
|
|
|
|
|
1; |