10 and is ran by Workers during the execution of eHive pipelines.
11 It is not generally supposed to be instantiated and used outside of
this framework.
19 This RunnableDB module is used to test failure of jobs in the hive system.
21 It is intended
for development/training purposes only.
25 param(
'value'): is essentially your job
's number.
26 If you are intending to create 100 jobs, let the param('value
') take consecutive values from 1 to 100.
28 param('divisor
'): defines the failure rate for this particular analysis. If the modulo (value % divisor) is 0, the job will fail.
29 For example, if param('divisor
')==5, jobs with 5, 10, 15, 20, 25,... param('value
') will fail.
31 param('state
'): defines the state in which the jobs of this analysis may be failing.
33 param('lethal_after
'): makes jobs' failures lethal when
'value' is greater than this parameter
35 param(
'time_FETCH_INPUT'): time in seconds that the job will spend sleeping in FETCH_INPUT state.
37 param(
'time_RUN'): time in seconds that the job will spend sleeping in RUN state.
39 param(
'time_WRITE_OUTPUT'): time in seconds that the job will spend sleeping in WRITE_OUTPUT state.
43 See the NOTICE file distributed with this work for additional information
44 regarding copyright ownership.
46 Licensed under the Apache License,
Version 2.0 (the
"License"); you may not use
this file except in compliance with the License.
47 You may obtain a copy of the License at
51 Unless required by applicable law or agreed to in writing, software distributed under the License
52 is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
53 See the License
for the specific language governing permissions and limitations under the License.
57 Please subscribe to the
Hive mailing list: http:
62 package Bio::EnsEMBL::Hive::Examples::FailureTest::RunnableDB::FailureTest;
67 use base (
'Bio::EnsEMBL::Hive::Process');
70 # die "Could not compile this nonsense!";
75 Description : Implements param_defaults()
interface method of
Bio::EnsEMBL::Hive::Process that defines module defaults for parameters.
82 'value' => 1, # normally you generate a batch of jobs with different values of param(
'value')
83 'divisor' => 2, # but the same param(
'divisor') and see how every param(
'divisor')
's job will crash
84 'state
' => 'RUN
', # the state in which the process may commit apoptosis ('FETCH_INPUT
', 'RUN
' or 'WRITE_OUTPUT
')
85 'lethal_after
' => 0, # If value is above this (nonzero) threshold, job's death becomes lethal to the worker.
87 'time_FETCH_INPUT' => 0, # how much time fetch_input() will spend in sleeping state
88 'time_RUN' => 1, # how much time
run() will spend in sleeping state
89 'time_WRITE_OUTPUT' => 0, # how much time write_output() will spend in sleeping state
91 'grab_mln' => 0, # how many millions of numeric elements to allocate
99 Function: sublcass can implement functions related to cleaning up the database/filesystem after the previous unsuccessful
run.
100 Here we just define it to see when the job gets into
this state.
110 Description : Implements fetch_input()
interface method of
Bio::EnsEMBL::Hive::Process that is used to read in parameters and load data.
111 Here it only calls dangerous_math() subroutine.
118 $self->dangerous_math(
'FETCH_INPUT');
124 Description : Implements
run()
interface method of
Bio::EnsEMBL::Hive::Process that is used to perform the
main bulk of the job (minus input and output).
125 Here it only calls dangerous_math() subroutine.
133 if(my $grab_mln = $self->param(
'grab_mln')) {
134 $mem_ref = $self->grab_memory( $grab_mln );
137 $self->dangerous_math(
'RUN');
143 Description : Implements write_output()
interface method of
Bio::EnsEMBL::Hive::Process that is used to deal with job's output after the execution.
144 Here it only calls dangerous_math() subroutine.
151 $self->dangerous_math(
'WRITE_OUTPUT');
158 Function: sublcass can implement functions related to cleaning up after running one job
159 (destroying non-trivial data structures in memory).
160 Here we just define it to see when the job gets into
this state.
165 # my $self = shift @_;
167 # $self->dangerous_math( $self->param('state') ); # uncomment to simulate failures in POST_CLEANUP
171 =head2 dangerous_math
173 Description: an
internal subroutine that will first sleep
for some predefined time,
174 and then either
return or crash
if $value is an integral multiple of $divisor.
179 my ($self, $current_state) = @_;
181 # First, sleep as required:
182 my $seconds_to_sleep = $self->param(
'time_'.$current_state);
183 sleep( $seconds_to_sleep );
185 my $state = $self->param(
'state');
186 return if($current_state ne $state);
188 my $value = $self->param(
'value') or die
"param('value') has to be a nonzero integer";
189 my $divisor = $self->param(
'divisor') or die
"param('divisor') has to be a nonzero integer";
191 if($value % $divisor == 0) {
193 if(my $lethal_after = $self->param(
'lethal_after')) {
194 if($value>$lethal_after) { # take the
Worker with us into the grave
195 $self->input_job->lethal_for_worker(1);
199 die
"Preprogrammed death since $value is a multiple of $divisor";
205 my ($self, $grab_mln) = @_;
207 my $elements = $grab_mln*1_000_000;
208 my $estimated_megs = $grab_mln*69 + 23; # empirically found by running on farm3, may differ elsewhere
212 $self->warning(
"Allocating $elements elements, which should map to approximately $estimated_megs megabytes");
214 my @mem = (1..$elements);