Skip to content

Commit d7b2f79

Browse files
authored
Minor change to remove temp files in the notify helper. (#159)
* Minor change to remove temp files in the notify helper. - This fixes an issue found where cromshell was filling /tmp disk space with the `notify` daemon. Not 100% sure why the trap didn't catch the temp files, but this fixes it.
1 parent 4787986 commit d7b2f79

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

cromshell

+26-7
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,8 @@ function assertCanCommunicateWithServer
455455
curl -s ${1}/api/workflows/v1/backends > ${f}
456456
grep -q 'supportedBackends' ${f}
457457
r=$?
458+
# Do some cleanup here for daemon processes.
459+
rm -f ${f}
458460
if [[ ${r} -ne 0 ]] ; then
459461
turtleDead
460462
error "Error: Cannot communicate with Cromwell server: ${serverName}"
@@ -524,8 +526,8 @@ function alias_workflow()
524526
function populateWorkflowIdAndServerFromAlias()
525527
{
526528
local alias_name=${1}
527-
WORKFLOW_ID=$(awk "BEGIN{FS=\"\t\"}{if (\$6 == \"${alias_name}\") {print}}" ${CROMWELL_SUBMISSIONS_FILE} | head -n1 | awk '{print $3}')
528-
WORKFLOW_SERVER_URL=$(awk "BEGIN{FS=\"\t\"}{if (\$6 == \"${alias_name}\") {print}}" ${CROMWELL_SUBMISSIONS_FILE} | head -n1 | awk '{print $2}')
529+
WORKFLOW_ID=$(awk "BEGIN{FS=\"\t\"}{if (\$6 == \"${alias_name}\") {print}}" ${CROMWELL_SUBMISSIONS_FILE} | head -n1 | awk '{print $3}')
530+
WORKFLOW_SERVER_URL=$(awk "BEGIN{FS=\"\t\"}{if (\$6 == \"${alias_name}\") {print}}" ${CROMWELL_SUBMISSIONS_FILE} | head -n1 | awk '{print $2}')
529531

530532
if [[ -z ${WORKFLOW_ID} ]]; then
531533
error "Invalid workflow/alias: ${alias_name}"
@@ -552,6 +554,9 @@ function populateWorkflowIdAndServerUrl()
552554
grep ${WORKFLOW_ID} ${CROMWELL_SUBMISSIONS_FILE} > ${tmpFile}
553555
r=$?
554556
[[ ${r} -eq 0 ]] && WORKFLOW_SERVER_URL=$( awk '{print $2}' ${tmpFile} )
557+
558+
# Do some cleanup here for daemon processes.
559+
rm -f ${tmpFile}
555560
else
556561
if [[ -n "$userSpecifiedId" ]]; then
557562
populateWorkflowIdAndServerFromAlias ${userSpecifiedId}
@@ -788,7 +793,7 @@ function submit()
788793

789794
assertCanCommunicateWithServer ${CROMWELL_URL}
790795

791-
echo "Submitting job to server: ${CROMWELL_URL}"
796+
echo "Submitting job to server: ${CROMWELL_URL}"
792797

793798
local response=$(curl -s -F workflowSource=@${wdl} ${2:+ -F workflowInputs=@${json}} ${3:+ -F workflowOptions=@${optionsJson}} ${4:+ -F workflowDependencies=@${dependenciesZip}} ${CROMWELL_URL}/api/workflows/v1)
794799
r=$?
@@ -848,7 +853,7 @@ function status()
848853
assertCanCommunicateWithServer ${2}
849854
local f=$( makeTemp )
850855
curl -s ${2}/api/workflows/v1/${1}/status > ${f}
851-
[[ $? -ne 0 ]] && error "Could not connect to Cromwell server." && return 2
856+
[[ $? -ne 0 ]] && error "Could not connect to Cromwell server." && rm -f ${f} && return 2
852857

853858
grep -qE '"Failed"|"Aborted"|"fail"' ${f}
854859
r=$?
@@ -900,6 +905,9 @@ function status()
900905
awk "BEGIN { FS=OFS=\"\t\" } { if ((\$3 == \"${1}\") && (\$2 == \"${2}\")) { \$5=\"${workflowStatus}\"; }; print }" ${CROMWELL_SUBMISSIONS_FILE}.bak > ${CROMWELL_SUBMISSIONS_FILE}
901906
#sed -i .bak -e "s#\\(.*${1}.*\\.wdl\\)\\t*.*#\\1$(printf '\t')${workflowStatus}#g" ${CROMWELL_SUBMISSIONS_FILE}
902907

908+
# Do some cleanup here for daemons:
909+
rm -f ${f} ${tmpExecutionStatusCount} ${tmpMetadata}
910+
903911
return ${retVal}
904912
}
905913

@@ -1009,6 +1017,9 @@ function execution-status-count()
10091017
jq '.. | .calls? | values | map_values(group_by(.executionStatus) | map({(.[0].executionStatus): . | length}) | add)' "${tempFile}"
10101018
checkPipeStatus "Could not read tmp file JSON data." "Could not parse JSON output from cromwell server."
10111019
fi
1020+
1021+
# Do some cleanup here for daemon processes.
1022+
rm -f ${tempFile}
10121023
done
10131024
}
10141025

@@ -1085,6 +1096,8 @@ function printTaskStatus()
10851096
failedShards=$(tr '\n' ' ' < ${tmpFailedShardsFile} | sed -E 's/\[( )+//' | sed -E 's/( )+\]//')
10861097
echo -e "${taskStatus}${indent}\tFailed shards: ${failedShards}${COLOR_NORM}"
10871098
fi
1099+
1100+
rm -f ${tmpFailedShardsFile} ${tmpStatusesFile}
10881101
}
10891102

10901103
# Bring up a browser window to view timing information on the job.
@@ -1530,7 +1543,8 @@ function notify()
15301543
# Send the script to the server:
15311544
local tmpOut=$( makeTemp )
15321545
scp ${SCRIPTDIR}/${SCRIPTNAME} ${hostServer}:~/. &> ${tmpOut}
1533-
[[ $? -ne 0 ]] && error "ERROR: Could not copy cromshell to server ${hostServer}" && error "$(cat ${tmpOut})" && exit 7
1546+
[[ $? -ne 0 ]] && error "ERROR: Could not copy cromshell to server ${hostServer}" && error "$(cat ${tmpOut})" && rm -f ${tmpOut} && exit 7
1547+
rm -f ${tmpOut}
15341548

15351549
# Spin off notification process on the server:
15361550
results=$( ssh ${hostServer} "~/${SCRIPTNAME} _rawNotify ${WORKFLOW_ID} ${email} ${WORKFLOW_SERVER_URL}" )
@@ -1583,6 +1597,11 @@ function _notifyHelper()
15831597
echo -e "CROMWELL Task ${completionStatus}:\n\n${id}\n\non\n\n${cromwellServer}\n\n${separator}\n\nStatus:\n$(cat ${statusFile})\n\n${separator}\nMetadata:\n${metaData}\n\n${separator}\nSent by $( whoami )@$( hostname ) on $( date ) \n\n\n" | mail -n -s "Cromwell Task ${completionStatus} [${cromwellServer}] ${workflowFile}" ${email}
15841598
break
15851599
fi
1600+
# Clean the temporary file just in case.
1601+
# This might need to happen because of how this helper gets called.
1602+
# Not sure the trap is working properly (i.e. it doesn't seem to be calling at_exit).
1603+
rm -f ${statusFile}
1604+
15861605
# wait for 10 seconds:
15871606
sleep 10
15881607
done
@@ -1900,8 +1919,8 @@ if ${ISINTERACTIVESHELL} ; then
19001919
esac
19011920

19021921
# Don't check JQ version if we're notifying.
1903-
# Why do this, you might ask?
1904-
# Because it's easier to hack our code than to get Broad IT to update software on our servers.
1922+
# Why do this, you might ask?
1923+
# Because it's easier to hack our code than to get Broad IT to update software on our servers.
19051924
if [[ "${SUB_COMMAND_FOR_DISPLAY}" != "notify" ]] ; then
19061925
checkJQVersion
19071926
r=$?

0 commit comments

Comments
 (0)