package APKPM::Bitstream;

use base qw(Gearman::Driver::Worker);
use Moose;
use Time::HiRes;
use Data::Dump qw(dump);
use LWP::Simple;
use JSON::XS;

with 'APKPM::Gearman';

sub prefix { 'Bitstream_' }

sub process_name {
	my ( $self, $orig, $job_name ) = @_;
	warn "# process_name $orig $job_name\n";
	return "$orig ($job_name)";
}

sub poll : Job : Encode(e_json) {
	my ( $self, $job, $workload ) = @_;

	my $content = get 'http://172.18.0.38/bs_ip_lookup';
	my $json = decode_json $content;

	my @users;

	foreach my $cpe ( @{ $json->{bs_ip_lookup} } ) {
		if ( $cpe->{username} =~ m/h1dsl-flat/ ) {
			warn "SKIP: ",dump($cpe) if $ENV{DEBUG};
		} else {
			push @users, $cpe;
		}
	}

	warn "# poll = ",dump( @users );

	return [ @users ];
}

1;
