-
Notifications
You must be signed in to change notification settings - Fork 2
/
gv_consume
executable file
·57 lines (48 loc) · 1.21 KB
/
gv_consume
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/perl
#
# ./gv_consume --dsn="DBI:mysql:job:host=127.0.0.1;database=job" \
# --username="job" --password="job" --gearmand="127.0.0.1:7003"
# For low latency mode, add:
# --pure
# ... and --dsn/etc become optional.
#
use strict;
use warnings;
use FindBin '$Bin';
use lib "$Bin/lib";
use Getopt::Long;
use Garivini::Client;
use Gearman::Worker;
use JSON;
my %o = ();
GetOptions(\%o,
'gearmand=s@',
'dsn=s',
'username=s',
'password=s',
'pure',
);
die "Need dsn" unless $o{dsn};
my $sm_client;
my $count = 0;
run();
sub run {
$sm_client = Garivini::Client->new(
dbs => {1 => { id => 1, dsn => $o{dsn}, user => $o{username},
pass => $o{password}, }},
);
my $worker = Gearman::Worker->new;
$worker->job_servers(@{$o{gearmand}});
$worker->register_function('foo' => \&consume_thing);
$worker->work;
}
sub consume_thing {
my $job = decode_json(${$_[0]->argref});
#print "Hay it's a job: ", $job->{arg}, "\n" if $count++ % 100 == 0;
print "Hay it's a job: ", $job->{arg}, "\n";
# If we're running in "pure gearman" mode, let the remote ControllerWorker
# complete the job.
unless ($o{pure}) {
$sm_client->complete_job($job);
}
}