Skip to content

Commit

Permalink
garbage collection repaired
Browse files Browse the repository at this point in the history
  • Loading branch information
TimoKramer committed Feb 23, 2020
1 parent 2036b96 commit 4298a4f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
20 changes: 10 additions & 10 deletions src/bob/pipeline/internals.clj
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
[taoensso.timbre :as log]
[cheshire.core :as json]
[mount.core :as m]
[bob.execution.internals :as e]
[bob.util :as u]
[bob.resource.core :as r]
[bob.artifact.core :as artifact]
[bob.states :as states]
[bob.artifact.core :as artifact]
[bob.execution.internals :as e]
[bob.pipeline.db :as db]
[bob.resource.core :as r]
[bob.resource.db :as rdb])
(:import (com.impossibl.postgres.jdbc PGDataSource)
(com.impossibl.postgres.api.jdbc PGNotificationListener
Expand All @@ -45,11 +45,12 @@
(if (nil? new-images) (list image) new-images))))

(defn gc-images
"garbage-collect images by run-id."
[run-id]
(log/debugf "Deleting all images for run %s" run-id)
(f/try* (run! #(e/delete-container %)
(get @images-produced run-id)))
(swap! images-produced dissoc run-id))
(let [_ (log/debugf "Deleting all images for run %s" run-id)
result (f/try* (run! #(e/delete-image %)
(get @images-produced run-id)))]
(swap! images-produced dissoc run-id)))

(defn update-pid
"Sets the current container id in the runs tables.
Expand Down Expand Up @@ -199,8 +200,7 @@
id (update-pid id run-id)
id (let [result (e/run id run-id)]
(when (f/failed? result)
(log/debugf "Removing failed container %s" id)
(e/delete-container states/docker-conn id))
(e/delete-container id))
result)
build-state (reduce (partial exec-step run-id evars pipeline number)
{:id id
Expand All @@ -209,7 +209,7 @@
[])}
(rest steps))
_ (log/debug "Removing last successful container")
_ (e/delete-container states/docker-conn (:id build-state))
_ (e/delete-container (:id build-state))
_ (log/infof "Marking run %d for %s as passed" number pipeline)
_ (gc-images run-id)
_ (db/update-run states/db
Expand Down
5 changes: 3 additions & 2 deletions test/bob/pipeline/internals_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@
(with-redefs [bob.pipeline.internals/images-produced (atom {"build1" (list "image2" "image1")})]
(is (= {"build1" (list "image2" "image1")
"build2" (list "image1")}
(mark-image-for-gc "image1" "build2")))))
(mark-image-for-gc "image1" "build2"))))))

(deftest gc-images-test
(testing "sweep images for build1"
(with-redefs [bob.pipeline.internals/images-produced (atom {"build1" (list "image2" "image1")
"build2" (list "image1")})]
(with-redefs-fn {#'e/delete-container (fn [_ image]
(with-redefs-fn {#'e/delete-image (fn [image]
(tu/check-and-fail
#(some #{image} ["image1" "image2"])))}
#(is (= {"build2" (list "image1")}
Expand Down

0 comments on commit 4298a4f

Please sign in to comment.