e336d4ad96a04792f5a6cf3a9d39b0f133742e4f
[nodejs-repoproxy.git] / lib / maintain.js
1 var fs = require("fs");
2 var http = require("http");
3 var url = require("url");
4 var path = require("path");
5 var repoapt = require("./repo-apt.js");
6 var repoyum = require("./repo-yum.js");
7
8 function maintainCache() {
9         // TODO i should check that im already running here and exit if i am
10         console.log("Cache maintainence routine starting...");
11         for(var index in global.repoproxy.repo) {
12                 console.log("start cleanup in ", index);
13                 console.log("cleanup array ", global.repoproxy.repo[index]);
14                 switch(global.repoproxy.repo[index]["type"]) {
15                 case "apt":
16                         console.log("Scanning '%s' as apt", index);
17                         repoapt.maintain(global.repoproxy.repo[index]);
18                         break;
19                 case "yum":
20                         console.log("Scanning '%s' as apt", index);
21                         repoyum.maintain(global.repoproxy.repo[index]);
22                         break;
23                 }
24         }
25         console.log("Cache maintainence routine ended...");
26 }
27
28 exports.startTimer = function() {
29         // our once-a-day cache maintainer
30         var cacheTimer = global.repoproxy.scancache*3600*1000;
31         //var cacheTimer = global.repoproxy.scancache*100;
32         maintainCache();
33         setInterval(maintainCache, cacheTimer);
34 }
35
36 function cleanupRoutine() {
37         
38 }