Skip to content

Redis working #1348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions api/v1/controllers/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* api/v1/controllers/register.js
*/

const logger = require('@salesforce/refocus-logging-client');
const configuredPassport = require('../../../express').passportModule;
const httpStatus = require('../constants').httpStatus;
const u = require('../helpers/verbs/utils');
Expand All @@ -30,15 +31,19 @@ module.exports = {
*
*/
registerUser(req, res, next) {
logger.info('registerUser');
if (featureToggles.isFeatureEnabled('rejectLocalUserRegistration')) {
logger.info('rejectLocalUserRegistration');
const forbidden = new apiErrors.ForbiddenError({
explanation: 'New user registration is not permitted.',
});
return u.handleError(next, forbidden, resourceName);
}

const resultObj = { reqStartTime: req.timestamp };
logger.info('resultObj', resultObj);
configuredPassport.authenticate('local-signup', (err, user) => {
logger.info('configuredPassport');
resultObj.dbTime = new Date() - resultObj.reqStartTime;
if (err) {
return u.handleError(next, err, resourceName);
Expand Down
2 changes: 2 additions & 0 deletions api/v1/controllers/samples.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ module.exports = {
* indicating merely that the bulk upsert request has been received.
*/
bulkUpsertSample(req, res, next) {
console.log('bulkUpsertSample');
const resultObj = { reqStartTime: req.timestamp };
const value = req.swagger.params.queryBody.value;
const body = { status: 'OK' };
Expand All @@ -479,6 +480,7 @@ module.exports = {
* with status and body
*/
function bulkUpsert(user) {
console.log('bulkUpsert', user);
if (featureToggles.isFeatureEnabled('enableWorkerProcess')) {
const jobType = require('../../../jobQueue/setup').jobType;
const jobWrapper = require('../../../jobQueue/jobWrapper');
Expand Down
5 changes: 5 additions & 0 deletions api/v1/controllers/subjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ module.exports = {
* @param {Function} next - The next middleware function in the stack
*/
getSubjectHierarchy(req, res, next) {
console.log('getSubjectHierarchy');
const params = req.swagger.params;
const filterParams = ['subjectTags', 'aspectTags', 'aspect', 'status'];

Expand All @@ -326,6 +327,7 @@ module.exports = {

if (featureToggles.isFeatureEnabled('enableWorkerProcess')
&& featureToggles.isFeatureEnabled('enqueueHierarchy')) {
console.log('featureToggles if');
jobWrapper.createJob(jobType.getHierarchy, resultObj, req)
.ttl(WORKER_TTL)
.on('complete', (resultObj) => {
Expand Down Expand Up @@ -370,12 +372,15 @@ module.exports = {
u.handleError(next, newErr, subject.modelName);
});
} else {
console.log('featureToggles else');
doGetHierarchy(resultObj)
.then((resultObj) => {
console.log('doGetHierarchy', resultObj);
u.logAPI(req, resultObj, resultObj.retval);
res.status(httpStatus.OK).json(resultObj.retval);
})
.catch((err) => {
console.log('doGetHierarchy catch');
u.handleError(next, err, subject.modelName);
});
}
Expand Down
7 changes: 6 additions & 1 deletion api/v1/helpers/verbs/doGetHierarchy.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,23 @@ function doGetHierarchy(resultObj) {
excludedFields.forEach((f) => fields.push(f));
}

console.log('\n\n\nbefore findByKey');
return u.findByKey(helper, params, ['hierarchy'])
.then((o) => {
resultObj.dbEndTime = Date.now();
resultObj.dbTime = resultObj.dbEndTime - resultObj.dbStartTime;
resultObj.recordCount = 1;
let retval = u.responsify(o, helper, GET);
if (depth > ZERO) {
console.log('here depth');
retval = helper.deleteChildren(retval, depth);
}

console.log('resultObj', resultObj);
console.log('retval', retval);
// return resultObj;
return redisSubjectModel.completeSubjectHierarchy(retval, params)
.then((_retval) => {
console.log('inside completeSubjectHierarchy', _retval);
resultObj.retval = _retval;
excludedFields.forEach((f) => delete retval[f]);
return resultObj;
Expand Down
17 changes: 13 additions & 4 deletions cache/models/subject.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,24 +183,33 @@ function traverseHierarchy(res) {
traveHPromises.push(traverseHierarchy(res.children[i]));
}
}

console.log('\n\n traveHPromises', traveHPromises);
return Promise.all(traveHPromises)
.then((values) => {
/*
* the resolved values from each of the promises is used to check if that
* node needs to be added to the final list of children
*/
console.log('\n\n values', values);
console.log('\n\n\n res', res.children);
for (let i = 0; i < values.length; i++) {
if (values[i]) {
filteredChildrenArr.push(res.children[i]);
console.log('\n inside values array ==>>>>', values[i]);
console.log('\n filteredChildrenArr while pushing ==>>>>', filteredChildrenArr);
}
}

console.log('\n filteredChildrenArr after push ==>>>>', filteredChildrenArr);
res.children = filteredChildrenArr.length ? filteredChildrenArr : undefined;

return attachSamples(res);
})
.then((ret) => Promise.resolve(ret || filteredChildrenArr.length));
.then((ret) => Promise.resolve(ret || filteredChildrenArr.length))
.catch((error) => {
// Handle errors here or propagate them up the promise chain
console.error('\n\n\n\n\n\n\n\n\n********Error in traverseHierarchy:', error);
throw error; // Propagate the error
});
} // traverseHierarchy

/**
Expand Down Expand Up @@ -236,7 +245,7 @@ function completeSubjectHierarchy(res, params) {
logger.info('cache/model/subject.completeSubjectHierarchy:' +
`${res.absolutePath}:${new Date() - startTime}`);
}

console.log('\n\n inside traverseHierarchy then', res);
return Promise.resolve(res);
});
} // completeSubjectHierarchy
Expand Down
16 changes: 13 additions & 3 deletions cache/redisCache.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/**
* Copyright (c) 2016, salesforce.com, inc.
* All rights reserved.
Expand Down Expand Up @@ -30,6 +31,8 @@ const opts = {
/* Redis Client Retry Strategy */
retry_strategy: (options) => {

console.log('\n\nRetry Strategy Options: ==>>>', options);
console.log('\n rconf.retryStrategy', rconf.retryStrategy);
/*
* Stop retrying if we've exceeded the configured threshold since the last
* successful connection. Flush all commands with a custom error message.
Expand All @@ -54,9 +57,10 @@ const opts = {
return Math.min(options.attempt * rconf.retryStrategy.backoffFactor,
rconf.retryStrategy.backoffMax);
}, // retryStrategy
tls: {
rejectUnauthorized: false
},
// tls: {
// // rejectUnauthorized: false
// connectTimeout: 10000, // Set the connection timeout to 5 seconds (adjust as needed)
// },
};

if (featureToggles.isFeatureEnabled('enableRedisConnectionLogging')) {
Expand All @@ -66,6 +70,7 @@ if (featureToggles.isFeatureEnabled('enableRedisConnectionLogging')) {
const subPerspectives = [];
const pubPerspectives = [];
rconf.instanceUrl.pubsubPerspectives.forEach((rp) => {
logger.info('rp', rp);
// Only create subscribers here if we're doing real-time events from main app
if (!featureToggles.isFeatureEnabled('enableRealtimeApplication')) {
const s = redis.createClient(rp, opts);
Expand All @@ -83,6 +88,8 @@ if (!featureToggles.isFeatureEnabled('enableRealtimeApplicationImc')) {
subBot.subscribe(rconf.botChannelName);
}

logger.info('rconf', rconf);

const client = {
cache: redis.createClient(rconf.instanceUrl.cache, opts),
clock: redis.createClient(rconf.instanceUrl.clock, opts),
Expand All @@ -97,6 +104,9 @@ const client = {
subBot,
};

console.log('client', client);
console.log('\n\ncache client', client.cache);

/**
* Register redis client handlers.
*
Expand Down
6 changes: 6 additions & 0 deletions cache/sampleStoreTimeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ const sampleEvent = require('../realtime/constants').events.sample;
const helper = require('../api/v1/helpers/nouns/samples');
const model = require('./models/samples');
const IORedis = require('ioredis');
const redisConfig = {
// tls: {
// // rejectUnauthorized: false
// connectTimeout: 10000, // Set the connection timeout to 5 seconds (adjust as needed)
// }
};
const ioredisClient = new IORedis(rconf.instanceUrl.sampleStore);
const featureToggles = require('feature-toggles');
const ONE = 1;
Expand Down
4 changes: 4 additions & 0 deletions config/passportconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
*/
'use strict'; // eslint-disable-line strict

const logger = require('@salesforce/refocus-logging-client');
const LocalStrategy = require('passport-local').Strategy;
const User = require('../db/index').User.scope('withSensitiveInfo');
const Profile = require('../db/index').Profile;
const bcrypt = require('bcrypt-nodejs');

module.exports = (passportModule) => {
logger.info('passportModule');
// used to serialize the user for the session
passportModule.serializeUser((user, done) => {
done(null, user);
Expand All @@ -37,10 +39,12 @@ module.exports = (passportModule) => {
* @param {Function} done - Callback function
*/
function signupStrategy(req, userName, userPassword, done) {
logger.info('signupStrategy');
// to do: We need to create default profiles in db.
// find user with this email
User.findOne({ where: { name: userName } })
.then((foundUser) => {
logger.info('findOne');
// if sso user, then update password and sso boolean.
if (foundUser) {
if (foundUser.sso === true) {
Expand Down
1 change: 1 addition & 0 deletions express.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ if (isDevelopment) {
logger.info(listening, PORT);
});
} else {
logger.info('express.js ');
serverApp = httpServer.listen(PORT, () => {
logger.info(listening, PORT);
});
Expand Down
Loading