Skip to content

Commit

Permalink
Delete files after successful processing. See #122
Browse files Browse the repository at this point in the history
  • Loading branch information
katauber committed Jan 12, 2024
1 parent 124a53b commit 90f0902
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/clj/metafacture_playground/process.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
(ns metafacture-playground.process
(:require
[clojure.string :as clj-str]
[clojure.tools.logging :as log])
[clojure.tools.logging :as log]
[clojure.java.io :as io])
(:import
(java.io File)
(org.metafacture.runner Flux)))
Expand All @@ -20,17 +21,28 @@
(log/trace "Content" content)
file-path))))

(defn- delete-files! [file-pathes]
(doseq [file-path file-pathes]
(try
(io/delete-file file-path)
(log/info "Deleted file " file-path)
(catch Exception e
(log/warn "Could not delete file " file-path ". Catched exception: " (.getMessage e))))))


(defn process [flux data transformation]
(let [inputfile (content->tempfile-path data ".data")
transformationFile (content->tempfile-path transformation ".fix")
transformationfile (content->tempfile-path transformation ".fix")
out-path (content->tempfile-path "" ".txt")
output (str "|write(\"" out-path "\");")
flux (-> (str "default inputFile = \"" inputfile "\";\n"
"default transformationFile = \"" transformationFile "\";\n"
"default transformationFile = \"" transformationfile "\";\n"
flux)
(clj-str/replace #"\|(\s*|\n*)write\(\".*\"\)(\s*|\n*);" output)
(clj-str/replace #"\|(\s*|\n*)print(\s*|\n*);" output))]
(Flux/main (into-array [(content->tempfile-path flux ".flux")]))
(clj-str/replace #"\|(\s*|\n*)print(\s*|\n*);" output))
fluxfile (content->tempfile-path flux ".flux")]
(Flux/main (into-array [fluxfile]))
(log/info "Executed flux file with Flux/main. Result in" out-path)
(slurp out-path)))
(let [result (slurp out-path)]
(delete-files! [inputfile transformationfile fluxfile out-path])
result)))

0 comments on commit 90f0902

Please sign in to comment.