buildJobDescriptor static method

Map<String, Object?> buildJobDescriptor(
  1. CubeResourceLimits limits
)

Computes the Job Object limit descriptor for limits:

  • memoryBytesprocessMemoryFlag plus processMemoryLimitBytes.
  • cpu as a percentage ("50%") → cpuRateFlag plus cpuRate (percent × 100; 50% → 5000). Other cpu spellings (bare fractions) have no mapping yet and are omitted.
  • timeouttimeoutMilliseconds (wall clock, enforced by the job runner's timer rather than a Job Object flag).
  • killOnJobCloseFlag is always set.

With no limits at all the flags word is 0.

Implementation

static Map<String, Object?> buildJobDescriptor(CubeResourceLimits limits) {
  var flags = killOnJobCloseFlag;
  final cpu = limits.cpu;
  final cpuPercent = cpu == null
      ? null
      : cpu.endsWith('%')
      ? double.tryParse(cpu.substring(0, cpu.length - 1))
      : null;
  if (cpuPercent != null) flags |= cpuRateFlag;
  final memoryBytes = limits.memoryBytes;
  if (memoryBytes != null) flags |= processMemoryFlag;
  return {
    'flags': flags,
    'processMemoryLimitBytes': ?memoryBytes,
    if (cpuPercent != null) 'cpuRate': (cpuPercent * 100).round(),
    'timeoutMilliseconds': ?limits.timeout?.inMilliseconds,
  };
}