问题描述
我正在尝试使用 ISO 8601 持续时间格式将 maxWallClockTime
设置为 72 小时。此属性的 documentation 没有用,因此我的猜测基于使用 8601 格式,因为这是在使用 CLI 时在 Batch Job level 处设置相同属性的方法。我的约束对象如下:
const taskConstraints = {
maxWallClockTime: 'P3D' //ISO 8601 Duration Format e.g. P3Y6M4DT12H30M5S represents a duration of three years,six months,four days,twelve hours,thirty minutes,and five seconds.
};
然而,这会导致以下错误:
task.constraints.maxWallClockTime must be a TimeSpan/Duration.
我找不到任何设置此属性并使用 Javascript API 的示例,任何指向更好文档或示例代码的指针将不胜感激。
解决方法
同意这里缺少文档。我还没有在本地对此进行测试,但是从查看代码我相信答案取决于您使用的是旧的 Node.js 特定的 azure-batch 包还是更新的 @azure/batch 也运行在网络浏览器中。
对于“azure-batch”包,它看起来像是需要一个 Moment.js 持续时间对象。这是相关的 JSDoc 字符串:
* @property {moment.duration} [maxWallClockTime] The maximum elapsed time
* that the Task may run,measured from the time the Task starts. If the Task
* does not complete within the time limit,the Batch service terminates it.
* If this is not specified,there is no time limit on how long the Task may
* run.
对于较新的“@azure/batch”包,它应该采用 ISO-8601 持续时间字符串。如果您正在使用该软件包,那么您尝试使用的值在我看来是正确的,并且可能是一个错误(我必须尝试对其进行重现)。