13219: Checks for expired run time and cancel container if needed.
[arvados.git] / sdk / go / dispatch / dispatch.go
index 3289c67b013f37a67ae8ddeaa52d3fd74abe34e5..ca2dbc48d4053f4e3036f0db6bcdaf4e03a0e064 100644 (file)
@@ -195,6 +195,13 @@ func (d *Dispatcher) checkListForUpdates(containers []arvados.Container, todo ma
                        case Queued:
                                tracker.close()
                        case Locked, Running:
+                               if c.SchedulingParameters.MaxRunTime > 0 {
+                                       maxRunTime := time.Duration(c.SchedulingParameters.MaxRunTime) * time.Second
+                                       if time.Since(c.StartedAt) >= maxRunTime {
+                                               // Time's up, schedule container for cancellation
+                                               c.Priority = 0
+                                       }
+                               }
                                tracker.update(c)
                        case Cancelled, Complete:
                                tracker.close()