adding the cleanup routines
[nodejs-repoproxy.git] / lib / maintain.js
diff --git a/lib/maintain.js b/lib/maintain.js
new file mode 100644 (file)
index 0000000..e336d4a
--- /dev/null
@@ -0,0 +1,38 @@
+var fs = require("fs");
+var http = require("http");
+var url = require("url");
+var path = require("path");
+var repoapt = require("./repo-apt.js");
+var repoyum = require("./repo-yum.js");
+
+function maintainCache() {
+       // TODO i should check that im already running here and exit if i am
+       console.log("Cache maintainence routine starting...");
+       for(var index in global.repoproxy.repo) {
+               console.log("start cleanup in ", index);
+               console.log("cleanup array ", global.repoproxy.repo[index]);
+               switch(global.repoproxy.repo[index]["type"]) {
+               case "apt":
+                       console.log("Scanning '%s' as apt", index);
+                       repoapt.maintain(global.repoproxy.repo[index]);
+                       break;
+               case "yum":
+                       console.log("Scanning '%s' as apt", index);
+                       repoyum.maintain(global.repoproxy.repo[index]);
+                       break;
+               }
+       }
+       console.log("Cache maintainence routine ended...");
+}
+
+exports.startTimer = function() {
+       // our once-a-day cache maintainer
+       var cacheTimer = global.repoproxy.scancache*3600*1000;
+       //var cacheTimer = global.repoproxy.scancache*100;
+       maintainCache();
+       setInterval(maintainCache, cacheTimer);
+}
+
+function cleanupRoutine() {
+       
+}
\ No newline at end of file