Merge branch 'devel' of h1dev:/srv/APKPM/
[APKPM.git] / lib / APKPM / Bitstream.pm
1 package APKPM::Bitstream;
2
3 use base qw(Gearman::Driver::Worker);
4 use Moose;
5 use Time::HiRes;
6 use Data::Dump qw(dump);
7 use LWP::Simple;
8 use JSON::XS;
9
10 with 'APKPM::Gearman';
11
12 sub prefix { 'Bitstream_' }
13
14 sub process_name {
15         my ( $self, $orig, $job_name ) = @_;
16         warn "# process_name $orig $job_name\n";
17         return "$orig ($job_name)";
18 }
19
20 sub poll : Job : Encode(e_json) {
21         my ( $self, $job, $workload ) = @_;
22
23         my $content = get 'http://172.18.0.38/bs_ip_lookup';
24         my $json = decode_json $content;
25
26         my @users;
27
28         foreach my $cpe ( @{ $json->{bs_ip_lookup} } ) {
29                 if ( $cpe->{username} =~ m/h1dsl-flat/ ) {
30                         warn "SKIP: ",dump($cpe) if $ENV{DEBUG};
31                 } else {
32                         push @users, $cpe;
33                 }
34         }
35
36         warn "# poll = ",dump( @users );
37
38         return [ @users ];
39 }
40
41 1;