line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MyCPAN::Indexer::Dispatcher::Serial; |
2
|
1
|
|
|
1
|
|
2265
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
37
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use parent qw(MyCPAN::Indexer::Component); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
6
|
1
|
|
|
1
|
|
68
|
use vars qw($VERSION $logger); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
61
|
|
7
|
|
|
|
|
|
|
$VERSION = '1.28_12'; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
6
|
use Log::Log4perl; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
9
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
BEGIN { |
12
|
1
|
|
|
1
|
|
74
|
$logger = Log::Log4perl->get_logger( 'Dispatcher' ); |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
MyCPAN::Indexer::Dispatcher::Serial - Pass out work in the same process |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Use this in C by specifying it as the queue class: |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# in backpan_indexer.config |
24
|
|
|
|
|
|
|
dispatch_class MyCPAN::Indexer::Dispatcher::Serial |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 DESCRIPTION |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
This class takes the list of distributions to process and passes them |
29
|
|
|
|
|
|
|
out to the code that will do the work. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head2 Methods |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=over 4 |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=item component_type |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
This is the dispatcher type. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
0
|
1
|
|
sub component_type { $_[0]->dispatcher_type } |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=item get_dispatcher |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Adds the C key with a code reference. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub get_dispatcher |
50
|
|
|
|
|
|
|
{ |
51
|
0
|
|
|
0
|
1
|
|
my( $self ) = @_; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
$self->get_coordinator->set_note( |
54
|
|
|
|
|
|
|
'interface_callback', |
55
|
|
|
|
|
|
|
$self->_make_interface_callback, |
56
|
|
|
|
|
|
|
) |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _make_interface_callback |
60
|
|
|
|
|
|
|
{ |
61
|
0
|
|
|
0
|
|
|
my( $self ) = @_; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my $Notes = {}; |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
$Notes->{$_} = [] foreach qw(PID recent errors ); |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
$Notes->{Total} = scalar @{ $self->get_note( 'queue' ) }; |
|
0
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
$Notes->{Left} = $Notes->{Total}; |
69
|
0
|
|
|
|
|
|
$Notes->{Errors} = 0; |
70
|
0
|
|
|
|
|
|
$Notes->{Done} = 0; |
71
|
0
|
|
|
|
|
|
$Notes->{Started} = scalar localtime; |
72
|
0
|
|
|
|
|
|
$Notes->{Finished} = 0; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
$Notes->{queue_cursor} = 0; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
foreach my $key ( keys %$Notes ) |
77
|
|
|
|
|
|
|
{ |
78
|
0
|
|
|
|
|
|
$self->set_note( $key, $Notes->{$key} ); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
$Notes->{interface_callback} = sub { |
82
|
0
|
|
|
0
|
|
|
$logger->debug( "Start: Finished: $Notes->{Finished} Left: $Notes->{Left}" ); |
83
|
|
|
|
|
|
|
|
84
|
0
|
0
|
|
|
|
|
unless( $self->get_note('Left') ) |
85
|
|
|
|
|
|
|
{ |
86
|
0
|
|
|
|
|
|
$self->set_note('Finished', 'true' ); |
87
|
0
|
|
|
|
|
|
return; |
88
|
|
|
|
|
|
|
}; |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
$self->set_note_unless_defined('_started', time); |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
$self->set_note('_elapsed', time - $self->get_note('_started') ); |
93
|
0
|
|
|
|
|
|
$self->set_note('Elapsed', _elapsed( $self->get_note('_elapsed') ) ); |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
my $item = ${ $self->get_note('queue') }[ $self->get_note('queue_cursor') ]; |
|
0
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
$self->increment_note( 'queue_cursor' ); |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
$self->increment_note( 'Done' ); |
99
|
0
|
|
|
|
|
|
$self->set_note('Left', $self->get_note('Total') - $self->get_note('Done') ); |
100
|
0
|
|
|
|
|
|
$logger->debug( |
101
|
|
|
|
|
|
|
sprintf "Total: %s Done: %s Left: %s Finished: %s", |
102
|
0
|
|
|
|
|
|
map { $self->get_note( $_ ) } qw(Total Done Left Finished) |
103
|
|
|
|
|
|
|
); |
104
|
|
|
|
|
|
|
|
105
|
1
|
|
|
1
|
|
766
|
no warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
238
|
|
106
|
|
|
|
|
|
|
$self->set_note('Rate', sprintf "%.2f / sec ", |
107
|
0
|
|
|
|
|
|
eval { $self->get_note('Done') / $self->get_note('_elapsed') } |
|
0
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
); |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
my $info = $self->get_note('child_task')->( $item ); |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
$info; |
113
|
0
|
|
|
|
|
|
}; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
BEGIN { |
118
|
1
|
|
|
1
|
|
40
|
my %hash = ( days => 864000, hours => 3600, minutes => 60 ); |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub _elapsed |
121
|
|
|
|
|
|
|
{ |
122
|
0
|
|
|
0
|
|
|
my $seconds = shift; |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
my @v; |
125
|
0
|
|
|
|
|
|
foreach my $key ( qw(days hours minutes) ) |
126
|
|
|
|
|
|
|
{ |
127
|
0
|
|
|
|
|
|
push @v, int( $seconds / $hash{$key} ); |
128
|
0
|
|
|
|
|
|
$seconds -= $v[-1] * $hash{$key} |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
push @v, $seconds; |
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
sprintf "%dd %02dh %02dm %02ds", @v; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
1; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=back |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 SEE ALSO |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
MyCPAN::Indexer, MyCPAN::Indexer::Tutorial |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 SOURCE AVAILABILITY |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
This code is in Github: |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
git://github.com/briandfoy/mycpan-indexer.git |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 AUTHOR |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
brian d foy, C<< >> |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Copyright (c) 2010-2013, brian d foy, All Rights Reserved. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
You may redistribute this under the same terms as Perl itself. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=cut |
162
|
|
|
|
|
|
|
|