| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package WorkerManager::Client::TheSchwartz; |
|
2
|
1
|
|
|
1
|
|
1153
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
24
|
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
25
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
3
|
use DBI; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
28
|
|
|
6
|
1
|
|
|
1
|
|
352
|
use TheSchwartz::Simple; |
|
|
1
|
|
|
|
|
1906
|
|
|
|
1
|
|
|
|
|
22
|
|
|
7
|
1
|
|
|
1
|
|
6
|
use Module::Load (); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
12
|
|
|
8
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
302
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
|
11
|
0
|
|
|
0
|
0
|
|
my ($class, $args) = @_; |
|
12
|
|
|
|
|
|
|
# Old version had typo... |
|
13
|
0
|
|
0
|
|
|
|
my $dsn = $args->{dsn} || $args->{dns} || croak 'not specified dsn for worker manager'; |
|
14
|
0
|
|
0
|
|
|
|
my $user = $args->{user} || 'nobody'; |
|
15
|
0
|
|
0
|
|
|
|
my $pass = $args->{pass} || 'nobody'; |
|
16
|
0
|
|
0
|
|
|
|
my $opts = $args->{opts} || {}; |
|
17
|
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
my $client; |
|
19
|
0
|
0
|
|
|
|
|
if ($ENV{DISABLE_WORKER}) { |
|
20
|
0
|
|
|
|
|
|
Module::Load::load('TheSchwartz'); |
|
21
|
0
|
|
|
|
|
|
Module::Load::load('TheSchwartz::Job'); |
|
22
|
|
|
|
|
|
|
} else { |
|
23
|
0
|
|
|
|
|
|
my $dbh = DBI->connect($dsn, $user, $pass, {RaiseError => 1, %$opts}); |
|
24
|
0
|
|
|
|
|
|
$client = TheSchwartz::Simple->new([$dbh]); |
|
25
|
|
|
|
|
|
|
} |
|
26
|
0
|
|
|
|
|
|
bless { client => $client }, $class; |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub insert { |
|
30
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
31
|
0
|
|
|
|
|
|
my $funcname = shift; |
|
32
|
0
|
|
|
|
|
|
my $arg = shift; |
|
33
|
0
|
|
|
|
|
|
my $options = shift; |
|
34
|
|
|
|
|
|
|
|
|
35
|
0
|
0
|
|
|
|
|
my $job = $ENV{DISABLE_WORKER} ? TheSchwartz::Job->new : TheSchwartz::Simple::Job->new; |
|
36
|
0
|
|
|
|
|
|
$job->funcname($funcname); |
|
37
|
0
|
|
|
|
|
|
$job->arg($arg); |
|
38
|
0
|
|
0
|
|
|
|
$job->run_after($options->{run_after} || time); |
|
39
|
0
|
|
0
|
|
|
|
$job->grabbed_until($options->{grabbed_until} || 0); |
|
40
|
0
|
|
0
|
|
|
|
$job->uniqkey($options->{uniqkey} || undef); |
|
41
|
0
|
0
|
0
|
|
|
|
$job->priority($options->{priority} || undef) if($job->can('priority')); |
|
42
|
|
|
|
|
|
|
|
|
43
|
0
|
0
|
|
|
|
|
if ($ENV{DISABLE_WORKER}) { |
|
44
|
0
|
|
|
|
|
|
eval { |
|
45
|
0
|
|
|
|
|
|
Module::Load::load($funcname); |
|
46
|
0
|
|
|
|
|
|
$funcname->work($job); |
|
47
|
0
|
0
|
|
|
|
|
warn $@ if $@; |
|
48
|
0
|
|
|
|
|
|
return !$@; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
} else { |
|
51
|
0
|
|
|
|
|
|
return $self->{client}->insert($job) |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |