Skip to content

Commit 5c2e28b

Browse files
committed
Optionally export MEM_SIZE and MEM_UNIT for all standard backends.
1 parent 54e4308 commit 5c2e28b

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

backend/src/main/scala/cromwell/backend/standard/StandardAsyncExecutionActor.scala

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import org.apache.commons.lang3.exception.ExceptionUtils
4040
import shapeless.Coproduct
4141
import wom.callable.{AdHocValue, CommandTaskDefinition, ContainerizedInputExpression}
4242
import wom.expression.WomExpression
43+
import wom.format.MemorySize
4344
import wom.graph.LocalName
4445
import wom.values._
4546
import wom.{CommandSetupSideEffectFile, InstantiatedCommand, WomFileMapper}
@@ -431,9 +432,25 @@ trait StandardAsyncExecutionActor
431432
val errorOrGlobFiles: ErrorOr[List[WomGlobFile]] =
432433
backendEngineFunctions.findGlobOutputs(call, jobDescriptor)
433434

434-
lazy val environmentVariables = instantiatedCommand.environmentVariables map { case (k, v) =>
435-
s"""export $k="$v""""
436-
} mkString ("", "\n", "\n")
435+
lazy val environmentVariables = {
436+
/*
437+
Add `MEM_SIZE` and `MEM_UNIT` before the other environment variables on all backends that define a `memory`
438+
runtime attribute. As of May 2022 some backends may expose these same environment variables via other means where
439+
they are accessible elsewhere, for example within sidecar containers used for resource monitoring.
440+
*/
441+
val memoryEnvironmentVariables: List[(String, String)] =
442+
runtimeMemoryOption.toList.flatMap(runtimeMemory =>
443+
List(
444+
"MEM_SIZE" -> runtimeMemory.amount.toString,
445+
"MEM_UNIT" -> runtimeMemory.unit.toString
446+
)
447+
)
448+
val environmentVariables: List[(String, String)] =
449+
memoryEnvironmentVariables ++ instantiatedCommand.environmentVariables
450+
environmentVariables map { case (key, value) =>
451+
s"""export $key="$value""""
452+
} mkString ("", "\n", "\n")
453+
}
437454

438455
val shortId = jobDescriptor.workflowDescriptor.id.shortString
439456
// Give the out and error FIFO variables names that are unlikely to conflict with anything the user is doing.
@@ -759,6 +776,16 @@ trait StandardAsyncExecutionActor
759776
lazy val continueOnReturnCode: ContinueOnReturnCode =
760777
RuntimeAttributesValidation.extract(ContinueOnReturnCodeValidation.instance, validatedRuntimeAttributes)
761778

779+
/**
780+
* Returns the memory size for the job.
781+
*
782+
* @return the memory size for the job.
783+
*/
784+
lazy val runtimeMemoryOption: Option[MemorySize] = RuntimeAttributesValidation.extractOption(
785+
runtimeAttributesValidation = MemoryValidation.instance(),
786+
validatedRuntimeAttributes = validatedRuntimeAttributes
787+
)
788+
762789
/**
763790
* Returns the max number of times that a failed job should be retried, obtained by converting `maxRetries` to an Int.
764791
*/

0 commit comments

Comments
 (0)