From: paulr Date: Mon, 21 Jan 2013 08:39:40 +0000 (+1100) Subject: adding the cleanup routines X-Git-Url: http://git.pjr.cc/?a=commitdiff_plain;h=04f3190a0bcc430af31917456a957ecc80eb160b;p=nodejs-repoproxy.git adding the cleanup routines --- diff --git a/lib/cache.js b/lib/cache.js index 9e5e8da..b7f111d 100644 --- a/lib/cache.js +++ b/lib/cache.js @@ -3,19 +3,6 @@ var http = require("http"); var url = require("url"); var path = require("path"); -function maintainCache() { - // TODO i should check that im already running here and exit if i am - console.log("Cache maintainence routine starting..."); - 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; - setInterval(maintainCache, cacheTimer); -} - function upstreamRequest(unify) { // first do a head request console.log("upsteram as ", unify.requestFor); diff --git a/lib/maintain.js b/lib/maintain.js new file mode 100644 index 0000000..e336d4a --- /dev/null +++ b/lib/maintain.js @@ -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 diff --git a/lib/repo-apt.js b/lib/repo-apt.js new file mode 100644 index 0000000..f37f881 --- /dev/null +++ b/lib/repo-apt.js @@ -0,0 +1,5 @@ +function maintain(details) { + console.log("doing apt clean for ", details); +} + +exports.maintain = maintain; \ No newline at end of file diff --git a/lib/repo-yum.js b/lib/repo-yum.js new file mode 100644 index 0000000..18b383a --- /dev/null +++ b/lib/repo-yum.js @@ -0,0 +1,5 @@ +function maintain(details) { + console.log("doing yum clean for ", details); +} + +exports.maintain = maintain; \ No newline at end of file diff --git a/proxy.js b/proxy.js index 65cf726..dabbdec 100644 --- a/proxy.js +++ b/proxy.js @@ -2,6 +2,7 @@ var http = require("http"); var config = require("./lib/config.js"); var router = require("./lib/router.js"); var cache = require("./lib/cache.js"); +var maintain = require("./lib/maintain.js"); // first we load the config... @@ -10,7 +11,7 @@ config.loadConfig("./repos.conf"); console.log("Starting cache maintenance timer"); -cache.startTimer(); +maintain.startTimer(); // next we start our main request loop http.createServer(router.routeRequest).listen(global.repoproxy.listenPort);