« blib/lib/Event/ExecFlow/Callbacks.pm
↑ Summary
blib/lib/Video/DVDRip/Cluster/ExecFlowFrontend.pm »
| 1 | package Event::ExecFlow::Scheduler::SimpleMax; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use base qw ( Event::ExecFlow::Scheduler ); | ||
| 5 | |||
| 6 | sub get_max { shift->{max} } | ||
| 7 | sub get_cnt { shift->{cnt} } | ||
| 8 | |||
| 9 | sub set_max { shift->{max} = $_[1] } | ||
| 10 | sub set_cnt { shift->{cnt} = $_[1] } | ||
| 11 | |||
| 12 | sub new { | ||
| 13 | my $class = shift; | ||
| 14 | my %par = @_; | ||
| 15 | my ($max) = $par{'max'}; | ||
| 16 | |||
| 17 | return bless { | ||
| 18 | max => $max, | ||
| 19 | cnt => 0, | ||
| 20 | }, $class; | ||
| 21 | } | ||
| 22 | |||
| 23 | sub schedule_job { | ||
| 24 | my $self = shift; | ||
| 25 | my ($job) = @_; | ||
| 26 | |||
| 27 | my $state; | ||
| 28 | if ( $self->get_cnt >= $self->get_max ) { | ||
| 29 | $state = 'sched-blocked'; | ||
| 30 | } | ||
| 31 | elsif ( $job->get_type ne 'group' ) { | ||
| 32 | ++$self->{cnt}; | ||
| 33 | $state = 'ok'; | ||
| 34 | } | ||
| 35 | else { | ||
| 36 | $state = 'ok'; | ||
| 37 | } | ||
| 38 | |||
| 39 | return $state; | ||
| 40 | } | ||
| 41 | |||
| 42 | sub job_finished { | ||
| 43 | my $self = shift; | ||
| 44 | my ($job) = @_; | ||
| 45 | --$self->{cnt} if $job->get_type ne 'group'; | ||
| 46 | 1; | ||
| 47 | } | ||
| 48 | |||
| 49 | 1; | ||
| 50 | |||
| 51 | __END__ |