Meadow.pm 2.89 KB
Newer Older
1 2 3 4 5 6 7
# A Meadow is an abstract interface for one of several implementations of Workers' process manager.
#
# A Meadow knows how to check&change the actual status of Workers

package Bio::EnsEMBL::Hive::Meadow;

use strict;
8 9
use warnings;

10 11 12 13 14 15 16

sub new {
    my $class = shift @_;

    return bless { @_ }, $class;
}

17

18 19
sub type { # should return 'LOCAL' or 'LSF'
    my $class = shift @_;
20

21
    $class = ref($class) if(ref($class));
22

23
    return (reverse split(/::/, $class ))[0];
24 25
}

Leo Gordon's avatar
Leo Gordon committed
26 27 28 29 30 31 32 33 34
sub pipeline_name { # if set, provides a filter for job-related queries
    my $self = shift @_;

    if(scalar(@_)) { # new value is being set (which can be undef)
        $self->{'_pipeline_name'} = shift @_;
    }
    return $self->{'_pipeline_name'};
}

35 36 37 38 39 40 41 42 43
sub meadow_options {    # general options that different Meadows can plug into the submission command
    my $self = shift @_;

    if(scalar(@_)) {
        $self->{'_meadow_options'} = shift @_;
    }
    return $self->{'_meadow_options'} || '';
}

44 45 46 47 48 49
sub job_name_prefix {
    my $self = shift @_;

    return ($self->pipeline_name() ? $self->pipeline_name().'-' : '') . 'Hive';
}

Leo Gordon's avatar
Leo Gordon committed
50
sub generate_job_name {
Leo Gordon's avatar
Leo Gordon committed
51 52
    my ($self, $worker_count, $iteration, $rc_id) = @_;
    $rc_id ||= 0;
Leo Gordon's avatar
Leo Gordon committed
53

54 55
    return $self->job_name_prefix()
        ."${rc_id}_${iteration}"
Leo Gordon's avatar
Leo Gordon committed
56
        . (($worker_count > 1) ? "[1-${worker_count}]" : '');
Leo Gordon's avatar
Leo Gordon committed
57 58
}

59 60 61
sub responsible_for_worker {
    my ($self, $worker) = @_;

62
    return ($worker->meadow_type eq $self->type) && ($worker->meadow_name eq $self->name);
63 64
}

65
sub check_worker_is_alive_and_mine {
66 67 68 69 70 71 72 73 74 75 76 77 78
    my ($self, $worker) = @_;

    die "Please use a derived method";
}

sub kill_worker {
    my ($self, $worker) = @_;

    die "Please use a derived method";
}

# --------------[(combinable) means of adjusting the number of submitted workers]----------------------

79 80 81 82 83 84
sub total_running_workers_default_max {   # no default by default :)

    return undef;
}

sub total_running_workers_max { # if set and ->can('count_running_workers'),
85 86 87 88
                                  # provides a cut-off on the number of workers being submitted
    my $self = shift @_;

    if(scalar(@_)) { # new value is being set (which can be undef)
89
        $self->{'_total_running_workers_max'} = shift @_;
90
    }
91
    return $self->{'_total_running_workers_max'} || $self->total_running_workers_default_max();
92 93
}

94
sub pending_adjust { # if set and ->can('count_pending_workers_by_rc_id'),
95 96 97 98 99 100 101 102 103
                     # provides a cut-off on the number of workers being submitted
    my $self = shift @_;

    if(scalar(@_)) { # new value is being set (which can be undef)
        $self->{'_pending_adjust'} = shift @_;
    }
    return $self->{'_pending_adjust'};
}

104
sub submit_workers_max { # if set, provides a cut-off on the number of workers being submitted
105 106 107
    my $self = shift @_;

    if(scalar(@_)) { # new value is being set (which can be undef)
108
        $self->{'_submit_workers_max'} = shift @_;
109
    }
110
    return $self->{'_submit_workers_max'};
111 112 113
}

1;