From ad756fa6b84842bdd9a8587162cacb34d52a6fbf Mon Sep 17 00:00:00 2001
From: Leo Gordon <lg4@ebi.ac.uk>
Date: Fri, 2 Nov 2012 15:14:57 +0000
Subject: [PATCH] parametrically slow down the LongMult test pipeline using
 -take_time global parameter

---
 .../EnsEMBL/Hive/PipeConfig/LongMult_conf.pm  | 20 +++++++++++++++++++
 .../Hive/RunnableDB/LongMult/AddTogether.pm   |  4 ++++
 .../Hive/RunnableDB/LongMult/PartMultiply.pm  |  4 +++-
 .../EnsEMBL/Hive/RunnableDB/LongMult/Start.pm |  9 ++++++++-
 4 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/modules/Bio/EnsEMBL/Hive/PipeConfig/LongMult_conf.pm b/modules/Bio/EnsEMBL/Hive/PipeConfig/LongMult_conf.pm
index 782707237..2408d37bd 100644
--- a/modules/Bio/EnsEMBL/Hive/PipeConfig/LongMult_conf.pm
+++ b/modules/Bio/EnsEMBL/Hive/PipeConfig/LongMult_conf.pm
@@ -75,6 +75,8 @@ sub default_options {
 
         'first_mult'    => '9650156169',                    # the actual numbers to be multiplied can also be specified from the command line
         'second_mult'   =>  '327358788',
+
+        'take_time'     => 0,                               # how much time (in seconds) should each job take -- to slow things down
     };
 }
 
@@ -98,6 +100,24 @@ sub pipeline_create_commands {
 }
 
 
+=head2 pipeline_wide_parameters
+
+    Description : Interface method that should return a hash of pipeline_wide_parameter_name->pipeline_wide_parameter_value pairs.
+                  The value doesn't have to be a scalar, can be any Perl structure now (will be stringified and de-stringified automagically).
+                  Please see existing PipeConfig modules for examples.
+
+=cut
+
+sub pipeline_wide_parameters {
+    my ($self) = @_;
+    return {
+        %{$self->SUPER::pipeline_wide_parameters},          # here we inherit anything from the base class
+
+        'take_time' => $self->o('take_time'),
+    };
+}
+
+
 =head2 pipeline_analyses
 
     Description : Implements pipeline_analyses() interface method of Bio::EnsEMBL::Hive::PipeConfig::HiveGeneric_conf that defines the structure of the pipeline: analyses, jobs, rules, etc.
diff --git a/modules/Bio/EnsEMBL/Hive/RunnableDB/LongMult/AddTogether.pm b/modules/Bio/EnsEMBL/Hive/RunnableDB/LongMult/AddTogether.pm
index 774167d7c..fc63e8e23 100644
--- a/modules/Bio/EnsEMBL/Hive/RunnableDB/LongMult/AddTogether.pm
+++ b/modules/Bio/EnsEMBL/Hive/RunnableDB/LongMult/AddTogether.pm
@@ -33,6 +33,8 @@ use base ('Bio::EnsEMBL::Hive::Process');
 
     param('b_multiplier'):  The second long number (also a string of digits).
 
+    param('take_time'):     How much time to spend sleeping (seconds).
+
 =cut
 
 sub fetch_input {   # fetch all the (relevant) precomputed products
@@ -64,6 +66,8 @@ sub run {   # call the function that will compute the stuff
     my $product_pair = $self->param('product_pair');
 
     $self->param('result', _add_together($b_multiplier, $product_pair));
+
+    sleep( $self->param('take_time') );
 }
 
 =head2 write_output
diff --git a/modules/Bio/EnsEMBL/Hive/RunnableDB/LongMult/PartMultiply.pm b/modules/Bio/EnsEMBL/Hive/RunnableDB/LongMult/PartMultiply.pm
index 12a53d1f4..bdd5304b1 100644
--- a/modules/Bio/EnsEMBL/Hive/RunnableDB/LongMult/PartMultiply.pm
+++ b/modules/Bio/EnsEMBL/Hive/RunnableDB/LongMult/PartMultiply.pm
@@ -42,6 +42,8 @@ sub fetch_input {
 
     param('digit'):         A decimal digit that is a part of the second multiplier.
 
+    param('take_time'):     How much time to spend sleeping (seconds).
+
 =cut
 
 sub run {   # call the recursive function that will compute the stuff
@@ -52,7 +54,7 @@ sub run {   # call the recursive function that will compute the stuff
 
     $self->param('result', _rec_multiply($a_multiplier, $digit, 0) || 0);
 
-    sleep(1);   # slow it down a little
+    sleep( $self->param('take_time') );
 }
 
 =head2 write_output
diff --git a/modules/Bio/EnsEMBL/Hive/RunnableDB/LongMult/Start.pm b/modules/Bio/EnsEMBL/Hive/RunnableDB/LongMult/Start.pm
index 4d16398ad..c5b591437 100644
--- a/modules/Bio/EnsEMBL/Hive/RunnableDB/LongMult/Start.pm
+++ b/modules/Bio/EnsEMBL/Hive/RunnableDB/LongMult/Start.pm
@@ -37,6 +37,8 @@ use base ('Bio::EnsEMBL::Hive::Process');
 
     param('b_multiplier'):  The second long number (also a string of digits).
 
+    param('take_time'):     How much time to spend sleeping (seconds).
+
 =cut
 
 sub fetch_input {
@@ -58,16 +60,21 @@ sub fetch_input {
     $self->param('output_ids', \@output_ids);
 }
 
+
 =head2 run
 
     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).
-                  Here we don't have any real work to do, just input and output, so run() remains empty.
+                  Here we don't have any real work to do, just input and output, so run() just spends some time waiting.
 
 =cut
 
 sub run {
+    my $self = shift @_;
+
+    sleep( $self->param('take_time') );
 }
 
+
 =head2 write_output
 
     Description : Implements write_output() interface method of Bio::EnsEMBL::Hive::Process that is used to deal with job's output after the execution.
-- 
GitLab