8028: After getting list of Queued containers, instead of looking for containers...
authorradhika <radhika@curoverse.com>
Tue, 19 Jan 2016 17:16:51 +0000 (12:16 -0500)
committerradhika <radhika@curoverse.com>
Wed, 20 Jan 2016 17:36:02 +0000 (12:36 -0500)
services/crunch-dispatch-local/crunch-dispatch-local.go
services/crunch-dispatch-local/crunch-dispatch-local_test.go

index 9fb4cb9bad7e4cf9e1e6675ef65596880450ef96..2b7bd2492edbc7e11ac6d4d8db5ebb8ab763bbfc 100644 (file)
@@ -84,8 +84,7 @@ type Container struct {
 
 // ContainerList is a list of the containers from api
 type ContainerList struct {
-       ItemsAvailable int         `json:"items_available"`
-       Items          []Container `json:"items"`
+       Items []Container `json:"items"`
 }
 
 // Get the list of queued containers from API server and invoke run for each container.
@@ -101,7 +100,7 @@ func dispatchLocal(priorityPollInterval int, crunchRunCommand string) {
                return
        }
 
-       for i := 0; i < containers.ItemsAvailable; i++ {
+       for i := 0; i < len(containers.Items); i++ {
                log.Printf("About to run queued container %v", containers.Items[i].UUID)
                go run(containers.Items[i].UUID, crunchRunCommand, priorityPollInterval)
        }
@@ -113,7 +112,7 @@ func dispatchLocal(priorityPollInterval int, crunchRunCommand string) {
 // Set the container state to Running
 // If the container priority becomes zero while crunch job is still running, terminate it.
 func run(uuid string, crunchRunCommand string, priorityPollInterval int) {
-       cmd := exec.Command(crunchRunCommand, "--job", uuid)
+       cmd := exec.Command(crunchRunCommand, uuid)
 
        cmd.Stdin = nil
        cmd.Stderr = os.Stderr
@@ -146,7 +145,7 @@ func run(uuid string, crunchRunCommand string, priorityPollInterval int) {
                                } else {
                                        if container.Priority == 0 {
                                                priorityTicker.Stop()
-                                               cmd.Process.Kill()
+                                               cmd.Process.Signal(os.Interrupt)
                                                return
                                        }
                                }
@@ -168,7 +167,7 @@ func run(uuid string, crunchRunCommand string, priorityPollInterval int) {
                err = arv.Update("containers", uuid,
                        arvadosclient.Dict{
                                "container": arvadosclient.Dict{"state": "Complete"}},
-                       &container)
+                       nil)
                if err != nil {
                        log.Printf("Error updating container state to Complete for %v: %q", uuid, err)
                }
index 1d526b91cd32ccf03c4cd99b58c024a5a3d9e72d..997c63a003285b03cbe2dfba987a41d842f52dfd 100644 (file)
@@ -59,7 +59,7 @@ func (s *MockArvadosServerSuite) TearDownTest(c *C) {
 }
 
 func (s *TestSuite) Test_doMain(c *C) {
-       args := []string{"-poll-interval", "1", "-container-priority-poll-interval", "1", "-crunch-run-command", "echo"}
+       args := []string{"-poll-interval", "2", "-container-priority-poll-interval", "1", "-crunch-run-command", "echo"}
        os.Args = append(os.Args, args...)
 
        go func() {
@@ -70,6 +70,9 @@ func (s *TestSuite) Test_doMain(c *C) {
        err := doMain()
        c.Check(err, IsNil)
 
+       // Give some time for run goroutine to complete
+       time.Sleep(1 * time.Second)
+
        // There should be no queued containers now
        params := arvadosclient.Dict{
                "filters": [][]string{[]string{"state", "=", "Queued"}},
@@ -77,7 +80,7 @@ func (s *TestSuite) Test_doMain(c *C) {
        var containers ContainerList
        err = arv.List("containers", params, &containers)
        c.Check(err, IsNil)
-       c.Assert(containers.ItemsAvailable, Equals, 0)
+       c.Assert(len(containers.Items), Equals, 0)
 
        // Previously "Queued" container should now be in "Complete" state
        var container Container