-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit. Still need to work on the requirement that there be N…
…O race conditions where one process is trying to populate Redis from db while another process is trying to persist samples from Redis to db.
- Loading branch information
Showing
5 changed files
with
402 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
|
||
|
||
/** | ||
* Copyright (c) 2017, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or | ||
* https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
/** | ||
* api/v1/controllers/admin.js | ||
*/ | ||
'use strict'; // eslint-disable-line strict | ||
|
||
const featureToggles = require('feature-toggles'); | ||
const sampleStore = require('../../../cache/sampleStore'); | ||
const sampleStoreInit = require('../../../cache/sampleStoreInit'); | ||
const apiErrors = require('../apiErrors'); | ||
const httpStatus = require('../constants').httpStatus; | ||
const authUtils = require('../helpers/authUtils'); | ||
const u = require('../helpers/verbs/utils'); | ||
|
||
module.exports = { | ||
|
||
/** | ||
* POST /admin/sampleStore/rebuild | ||
* | ||
* Rebuild the redis sampleStore from the samples in the database. Admin | ||
* only. | ||
* | ||
* @param {IncomingMessage} req - The request object | ||
* @param {ServerResponse} res - The response object | ||
* @param {Function} next - The next middleware function in the stack | ||
*/ | ||
rebuildSampleStore(req, res, next) { | ||
authUtils.isAdmin(req) | ||
.then((ok) => { | ||
if (ok) { | ||
const enabled = featureToggles | ||
.isFeatureEnabled(sampleStore.constants.featureName); | ||
if (enabled) { | ||
sampleStoreInit.eradicate() | ||
.then(() => sampleStoreInit.populate()) | ||
.then(() => { | ||
res.status(httpStatus.NO_CONTENT).json(); | ||
}); | ||
} else { | ||
const err = new apiErrors.InvalidSampleStoreState({ | ||
explanation: 'You cannot rebuild the sample store if the ' + | ||
'ENABLE_REDIS_SAMPLE_STORE feature is not enabled.', | ||
}); | ||
next(err); | ||
} | ||
} else { | ||
u.forbidden(next); | ||
} | ||
}) | ||
.catch(() => u.forbidden(next)); | ||
}, | ||
|
||
}; // exports |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.