line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Games::Lacuna::Task::Role::RPCLimit; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1589
|
use 5.010; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
55
|
|
4
|
|
|
|
|
|
|
our $VERSION = $Games::Lacuna::Task::VERSION; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
455
|
use Moose::Role; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has 'force' => ( |
9
|
|
|
|
|
|
|
is => 'rw', |
10
|
|
|
|
|
|
|
isa => 'Bool', |
11
|
|
|
|
|
|
|
required => 1, |
12
|
|
|
|
|
|
|
default => 0, |
13
|
|
|
|
|
|
|
documentation => 'Run action even if RPC limit is almost spent', |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
around 'run' => sub { |
17
|
|
|
|
|
|
|
my $orig = shift; |
18
|
|
|
|
|
|
|
my $self = shift; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $rpc_limit_hard = $self->get_stash('rpc_limit'); |
21
|
|
|
|
|
|
|
my $rpc_limit_soft = int($rpc_limit_hard * 0.9); |
22
|
|
|
|
|
|
|
my $rpc_count = $self->get_stash('rpc_count'); |
23
|
|
|
|
|
|
|
my $task_name = Games::Lacuna::Task::Utils::class_to_name($self); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
if ($rpc_count > $rpc_limit_soft |
26
|
|
|
|
|
|
|
&& ! $self->force) { |
27
|
|
|
|
|
|
|
$self->log('warn',"Skipping action %s because RPC limit is almost reached (%i of %i)",$task_name,$rpc_count,$rpc_limit_hard); |
28
|
|
|
|
|
|
|
} elsif ($rpc_count >= $rpc_limit_hard) { |
29
|
|
|
|
|
|
|
$self->log('warn',"Skipping action %s because RPC limit is spent (%i)",$task_name,$rpc_limit_hard); |
30
|
|
|
|
|
|
|
} else { |
31
|
|
|
|
|
|
|
return $self->$orig(@_); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
}; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
no Moose::Role; |
36
|
|
|
|
|
|
|
1; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=encoding utf8 |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 NAME |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Games::Lacuna::Role::RPCLimit -Â Skip tasks if 90% RPC limit is reached |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 SYNOPSIS |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
package Games::Lacuna::Task::Action::MyTask; |
47
|
|
|
|
|
|
|
use Moose; |
48
|
|
|
|
|
|
|
extends qw(Games::Lacuna::Task::Action); |
49
|
|
|
|
|
|
|
with qw(Games::Lacuna::Task::Role::RPCLimit); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |