blib/lib/Schedule/Chronic/Constraint/Concurrent.pm untested

filter: Statementstmt 0.0% 0 / 28 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 59 CC 6 SCAR 26.6
CC
6
Cov
0%
init
30.0
met
6.0
new
2.0
CRAP 14.3
1 ##
2 ## DiskIO constraint
3 ## Author: Vipul Ved Prakash <mail@vipul.net>.
4 ## $Id: Concurrent.pm,v 1.1 2005/04/26 07:22:32 hackworth Exp $
5 ##
6  
7  
8 package Schedule::Chronic::Constraint::Concurrent;
9 use Schedule::Chronic::Base;
10 use base qw(Schedule::Chronic::Base);
11  
12  
13 sub new {
14
15 my ($class) = @_;
16  
17 return bless {
18 wait => 5,
19 }, $class;
20  
21 }
22  
23  
24 sub init {
25  
26 my ($self, $schedule, $task, $logger, $process, $concurrent) = @_;
27 return unless ($self and $process and $concurrent);
28  
29 $$self{schedule} = $schedule if $schedule;
30 $$self{task} = $task if $task;
31 $$self{active} = $active if $active;
32 $$self{process} = $process;
33 $$self{concurrent} = $concurrent;
34 $$self{logger} = $logger;
35  
36 return $self;
37  
38 }
39  
40  
41 sub met {
42  
43 my ($self) = @_;
44  
45 my ($number) = $self->state;
46  
47 $self->debug(" concurrent = $number $$self{process} processes");
48  
49 if ($number < $$self{concurrent}) {
50 return 1;
51 } else {
52 $self->{wait} = 10;
53 return 0;
54 }
55  
56 }
57  
58  
59 sub state {
60  
61 my ($self) = @_;
62  
63 my @number = `ps -C $$self{process}`;
64  
65 # Sample output:
66 # vipul@precog Constraint $ ps -C mutt
67 # PID TTY TIME CMD
68 # 6468 pts/1 00:00:00 mutt
69 # 6470 pts/1 00:00:00 mutt
70 # 9000 pts/1 00:00:00 mutt
71  
72 return (scalar @number - 1);
73  
74 }
75  
76  
77 sub wait {
78  
79 return $_[0]->{wait};
80  
81 }
82  
83  
84 1;
85  
86