diff --git a/tools/flush_cache b/tools/flush_cache new file mode 100755 index 00000000..fdf3bb83 --- /dev/null +++ b/tools/flush_cache @@ -0,0 +1,59 @@ +#!/usr/bin/env node + +var path = require('path'); +var request = require('request'); + +function usage(me, exitcode) { + console.log("Usage: " + me + " [--env ] "); + process.exit(exitcode); +} + +var node_path = process.argv.shift(); +var script_path = process.argv.shift(); +var basedir = path.dirname(script_path); +var me = path.basename(script_path); + +var ENV = 'development.js'; +var username, table; +var arg; +while ( arg = process.argv.shift() ) { + if ( arg == '--env' ) { + ENV = process.argv.shift(); + } + else if ( ! username ) { + username = arg; + } + else if ( ! table ) { + table = arg; + } + else { + console.warn("Unused parameter " + arg); + } +} + +if ( ! table ) { + usage(me, 1); +} + +global.environment = require('../config/environments/' + ENV); + +// _after_ setting global.environment +var serverOptions = require('../lib/cartodb/server_options'); + +var host = global.environment.host; +var port = global.environment.port; +var re = ''+serverOptions.re_userFromHost; +var hostname = re.replace(/^\/\^/, '') + .replace(/\/$$/, '') + .replace(/\\/g,'') + .replace(/\([^)]*\)/,username) + ; +//console.log("re: " + re); +//console.log("hostname: " + hostname); + +var url = 'http://' + host + ':' + port + '/tiles/' + table + '/flush_cache'; +request.del({ url: url, headers: { host: hostname } }, +function(err, res, body) { + if ( err ) throw err; + console.log(res.body); +});