diff --git a/lib/put.js b/lib/put.js index e153326ca..c93139274 100644 --- a/lib/put.js +++ b/lib/put.js @@ -21,32 +21,12 @@ const Result = { } const actionHandlers = {} -const actions = {} -var nextActionId = 1 - -const pruneActionTimeout = 60 * 60 * 1000 -const pruneInterval = 15 * 60 * 1000 module.exports = { start: function (app) { app.registerActionHandler = registerActionHandler app.deRegisterActionHandler = deRegisterActionHandler - setInterval(pruneActions, pruneInterval) - - app.get(apiPathPrefix + 'actions', function (req, res, next) { - res.json(actions) - }) - - app.get(apiPathPrefix + 'actions/:id', function (req, res, next) { - var action = actions[req.params.id] - if (!action) { - res.status(404).send() - } else { - res.json(action) - } - }) - app.put(apiPathPrefix + '*', function (req, res, next) { var path = String(req.path).replace(apiPathPrefix, '') @@ -225,31 +205,3 @@ function deRegisterActionHandler (context, path, source, callback) { debug(`de-registered action handler for ${context} ${path} ${source}`) } } - -function asyncCallback (actionId, status) { - var action = actions[actionId] - if (action) { - action.state = status.state - action.result = status.result - action['endTime'] = new Date().toISOString() - if (status.message) { - action.message = status.message - } - if (status.percentComplete) { - action.percentComplete = status.percentComplete - } - } -} - -function pruneActions () { - debug('pruning actions') - _.keys(actions).forEach(id => { - var action = actions[id] - - var diff = new Date() - new Date(action['end-time']) - if (diff > pruneActionTimeout) { - delete actions[id] - debug('pruned action %d', id) - } - }) -} diff --git a/lib/requestResponse.js b/lib/requestResponse.js index edc43b446..c534ebc3a 100644 --- a/lib/requestResponse.js +++ b/lib/requestResponse.js @@ -4,6 +4,12 @@ const _ = require('lodash') const requests = {} +// const pruneRequestTimeout = 60 * 60 * 1000 +// const pruneIntervalRate = 15 * 60 * 1000 +const pruneRequestTimeout = 10000 +const pruneIntervalRate = 1000 +var pruneInterval + function createRequest (type, clientRequest, user, clientIp, updateCb) { return new Promise((resolve, reject) => { let requestId = clientRequest.requestId ? clientRequest.requestId : uuidv4() @@ -19,6 +25,11 @@ function createRequest (type, clientRequest, user, clientIp, updateCb) { } requests[request.requestId] = request debug('createRequest %j', request) + + if (!pruneInterval) { + pruneInterval = setInterval(pruneRequests, pruneIntervalRate) + } + resolve(request) }) } @@ -98,6 +109,19 @@ function filterRequests (type, state) { ) } +function pruneRequests () { + debug('pruning requests') + _.keys(requests).forEach(id => { + var request = requests[id] + + var diff = new Date() - new Date(request.date) + if (diff > pruneRequestTimeout) { + delete requests[id] + debug('pruned request %s', id) + } + }) +} + module.exports = { createRequest, updateRequest,