Skip to content

Commit

Permalink
Optionally export MEM_SIZE and MEM_UNIT for all standard backends.
Browse files Browse the repository at this point in the history
  • Loading branch information
kshakir committed May 11, 2024
1 parent 430fc40 commit 61063cb
Showing 1 changed file with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import org.apache.commons.lang3.exception.ExceptionUtils
import shapeless.Coproduct
import wom.callable.{AdHocValue, CommandTaskDefinition, ContainerizedInputExpression}
import wom.expression.WomExpression
import wom.format.MemorySize
import wom.graph.LocalName
import wom.values._
import wom.{CommandSetupSideEffectFile, InstantiatedCommand, WomFileMapper}
Expand Down Expand Up @@ -427,9 +428,25 @@ trait StandardAsyncExecutionActor
val errorOrGlobFiles: ErrorOr[List[WomGlobFile]] =
backendEngineFunctions.findGlobOutputs(call, jobDescriptor)

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

val shortId = jobDescriptor.workflowDescriptor.id.shortString
// Give the out and error FIFO variables names that are unlikely to conflict with anything the user is doing.
Expand Down Expand Up @@ -755,6 +772,16 @@ trait StandardAsyncExecutionActor
lazy val continueOnReturnCode: ContinueOnReturnCode =
RuntimeAttributesValidation.extract(ContinueOnReturnCodeValidation.instance, validatedRuntimeAttributes)

/**
* Returns the memory size for the job.
*
* @return the memory size for the job.
*/
lazy val runtimeMemoryOption: Option[MemorySize] = RuntimeAttributesValidation.extractOption(
runtimeAttributesValidation = MemoryValidation.instance(),
validatedRuntimeAttributes = validatedRuntimeAttributes
)

/**
* Returns the max number of times that a failed job should be retried, obtained by converting `maxRetries` to an Int.
*/
Expand Down

0 comments on commit 61063cb

Please sign in to comment.