Commit 1bb5c1e0 authored by Karl Kornel's avatar Karl Kornel
Browse files

Move workflow-complete creation into a separate function.

We need to generate workflow-complete.txt for runs that have errors.
parent 312a3c5c
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -160,6 +160,26 @@ sub lock_release {
	return 1;
}

# workflow_complete: Create a file to avoid re-running workflow for a run.
# $runfolder: The path to the directory where the marker file should be placed.
sub workflow_complete {
    my ($runfolder) = @_;
	dolog("Creating workflow-complete.txt marker file\n");
	my $complete_path = "$runfolder/workflow-complete.txt";
	my $complete_handle;
	open($complete_handle, '>', $complete_path) or do {
		dolog(<<"EOF");
Unable to open the workflow-complete.txt file for writing!
Tried to open this file: $complete_path
Here is the error we received: $!
EOF
		return 0;
	};
	print $complete_handle 'Workflow completed at ', localtime(time()), "\n";
	close($complete_handle);
    return 1;
}


# End on a true value.
1;
+7 −13
Original line number Diff line number Diff line
@@ -281,6 +281,7 @@ EOL
	# If we timed out, then exit.
	if ($TIMEOUT1 == 0) {
		dolog("Gave up waiting for $RUNFOLDER/RTAComplete.txt\n");
        workflow_complete($RUNFOLDER);
		log_failure("Gave up waiting for RTAComplete.txt to appear",
		            'run', $RUNFOLDER, "$RealBin/email-recipients.txt",
		            $LOGPATH, $LOG);
@@ -297,6 +298,7 @@ Please make sure you are running this command with a valid run folder!
The directory we are trying to open is: $basecalls_path
The error we are getting is: $!
EOF
        workflow_complete($RUNFOLDER);
		return;
	};
	while (readdir($basecalls_handle)) {
@@ -345,6 +347,7 @@ There was a problem starting the analysis command.
The command we tried to run was $runcommand_string
The error we got was: $@
EOF
        workflow_complete($RUNFOLDER);
		email_failure('Problem starting the analysis command',
			      'run', $RUNFOLDER,
			      "$RealBin/email-recipients.txt", $LOGPATH,
@@ -369,6 +372,7 @@ EOF
		dolog("That's good! 8-)\n");
		email_analysis($RUNFOLDER, "$RealBin/email-recipients.txt",
		               $LOGPATH, $RealBin, $RealScript) or do {
            workflow_complete($RUNFOLDER);
			email_failure('Problems sending the post-analysis mail',
			              'run', $RUNFOLDER,
				      "$RealBin/email-recipients.txt", $LOGPATH,
@@ -376,25 +380,15 @@ EOF
		};
	} else {
		dolog("That's bad 8-(\n");
        workflow_complete($RUNFOLDER);
		email_failure('The analysis program had an error',
		              'run', $RUNFOLDER,
		              "$RealBin/email-recipients.txt", $LOGPATH, \$LOG,
		              $RealBin, $RealScript);
	}

	dolog("Creating workflow-complete.txt marker file\n");
	my $complete_path = "$RUNFOLDER/workflow-complete.txt";
	my $complete_handle;
	open($complete_handle, '>', $complete_path) or do {
		dolog(<<"EOF");
Unable to open the workflow-complete.txt file for writing!
Tried to open this file: $complete_path
Here is the error we received: $!
EOF
		return;
	};
	print $complete_handle 'Workflow completed at ', localtime(time()), "\n";
	close($complete_handle);
    # Create the completion marker
    workflow_complete($RUNFOLDER);
};


+14 −13
Original line number Diff line number Diff line
@@ -298,6 +298,7 @@ EOL
	# If we timed out, then exit.
	if ($TIMEOUT2 == 0) {
		dolog("Gave up waiting for $RUNFOLDER/RTAComplete.txt\n");
        workflow_complete($RUNFOLDER);
		email_failure("Gave up waiting for RTAComplete.txt to appear",
		              'run', $RUNFOLDER,
		              "$RealBin/email-recipients.txt", $LOGPATH, \$LOG,
@@ -321,6 +322,7 @@ EOL
	# If we timed out, then exit.
	if ($TIMEOUT2 == 0) {
		dolog("Gave up waiting for $RUNFOLDER/RunCompletionStatus.xml\n");
        workflow_complete($RUNFOLDER);
		email_failure("Gave up waiting for RunCompletionStatus.xml",
		              'run', $RUNFOLDER,
		              "$RealBin/email-recipients.txt", $LOGPATH, \$LOG,
@@ -337,6 +339,7 @@ We got an error when trying to open RunCompletionStatus.xml.
The full path we tried to open is: $RUNFOLDER/RunCompletionStatus.xml
The error we got is: $!
EOF
        workflow_complete($RUNFOLDER);
		email_failure("Could not open RunCompletionStatus.xml", 'run',
			      $RUNFOLDER, "$RealBin/email-recipients.txt",
			      $LOGPATH, \$LOG, $RealBin, $RealScript);
@@ -356,6 +359,7 @@ EOF
We have a completed run, but the CompletionStatus is not "CompletedAsPlanned".
The completion status we found is: $1
EOF
            workflow_complete($RUNFOLDER);
			email_failure("Un-good CompletionStatus", 'run',
				      $RUNFOLDER, 
				      "$RealBin/email-recipients.txt", $LOGPATH,
@@ -375,6 +379,7 @@ We got an error when trying to open RunParameters.xml.
The full path we tried to open is: $RUNFOLDER/RunParameters.xml
The error we got is: $!
EOF
        workflow_complete($RUNFOLDER);
		email_failure("Could not open RunParameters.xml", 'run',
			      $RUNFOLDER, "$RealBin/email-recipients.txt",
			      $LOGPATH, \$LOG, $RealBin, $RealScript);
@@ -394,6 +399,7 @@ EOF
		dolog(<<"EOF");
We were unable to find a LibraryID inside RunParameters.xml.
EOF
        workflow_complete($RUNFOLDER);
		email_failure("Could not find a LibraryID",
			      'run', $RUNFOLDER,
			      "$RealBin/email-recipients.txt", $LOGPATH, \$LOG,
@@ -408,6 +414,7 @@ EOF
Unable to access the Google Drive folder containing the samplesheets.
The folder we are trying to access is: $DRIVEPATH
EOF
        workflow_complete($RUNFOLDER);
		email_failure("Could not access gdrive folder", 'run',		                              $RUNFOLDER, "$RealBin/email-recipients.txt",
			      $LOGPATH, \$LOG, $RealBin, $RealScript);
		return;
@@ -442,6 +449,7 @@ EOF
	my $samplesheet_path;
	if (scalar(@samplesheets) == 0) {
		dolog("No samplesheets found!\n");
        workflow_complete($RUNFOLDER);
		email_failure("No samplesheets found for $LIBRARYID", 'run',
			      $RUNFOLDER, "$RealBin/email-recipients.txt",
			      $LOGPATH, \$LOG, $RealBin, $RealScript);
@@ -481,6 +489,7 @@ The file we tried to copy is: $samplesheet_path
The destination was: $RUNFOLDER/SampleSheet.csv
The error is: $!
EOF
        workflow_complete($RUNFOLDER);
		email_failure('Unable to copy SampleSheet.csv into place', 'run',
			      $RUNFOLDER, "$RealBin/email-recipients.txt",
			      $LOGPATH, \$LOG, $RealBin, $RealScript);
@@ -545,6 +554,7 @@ There was a problem starting the analysis command.
The command we tried to run was $runcommand_string
The error we got was: $@
EOF
        workflow_complete($RUNFOLDER);
		email_failure('Problem starting the analysis command',
			      'run', $RUNFOLDER,
			      "$RealBin/email-recipients.txt", $LOGPATH,
@@ -569,6 +579,7 @@ EOF
		dolog("That's good! 8-)\n");
		email_analysis($RUNFOLDER, "$RealBin/email-recipients.txt",
		               $LOGPATH, $RealBin, $RealScript) or do {
            workflow_complete($RUNFOLDER);
			email_failure('Problems sending the post-analysis mail',
			              'run', $RUNFOLDER,
				      "$RealBin/email-recipients.txt", $LOGPATH,
@@ -576,25 +587,15 @@ EOF
		};
	} else {
		dolog("That's bad 8-(\n");
        workflow_complete($RUNFOLDER);
		email_failure('The analysis program had an error',
		              'run', $RUNFOLDER,
		              "$RealBin/email-recipients.txt", $LOGPATH, \$LOG,
		              $RealBin, $RealScript);
	}

	dolog("Creating workflow-complete.txt marker file\n");
	my $complete_path = "$RUNFOLDER/workflow-complete.txt";
	my $complete_handle;
	open($complete_handle, '>', $complete_path) or do {
		dolog(<<"EOF");
Unable to open the workflow-complete.txt file for writing!
Tried to open this file: $complete_path
Here is the error we received: $!
EOF
		return;
	};
	print $complete_handle 'Workflow completed at ', localtime(time()), "\n";
	close($complete_handle);
    # Create the completion marker
    workflow_complete($RUNFOLDER);
};