Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// @flow
import Sequelize from 'sequelize'
import cls from 'continuation-local-storage'
const namespace = cls.createNamespace('my-db-namespace')
Sequelize['useCLS'](namespace)
const sequelize = new Sequelize('clinic', 'tester', 'password', {
host: 'localhost',
dialect: 'sqlite',
pool: {
max: 5,
min: 0,
idle: 10000
},
// SQLite only
storage: ':memory:',
logging: (str) => console.log(str),
define: {
underscored: true,
context.getRemainingTimeInMillis = () => {
const currentTime = new Date()
return timeout - (currentTime - startTime)
}
// The following three functions are deprecated in AWS Lambda.
// Since it is sometimes used by other SDK,
// it is a simple one that does not result in `not function` error
context.succeed = (result) => console.log(JSON.stringify(result))
context.fail = (error) => console.log(JSON.stringify(error))
context.done = (error, results) => {
console.log(JSON.stringify(error))
console.log(JSON.stringify(results))
}
const nameSpace = createNamespace('AWSXRay')
nameSpace.run(() => {
nameSpace.set('segment', new AWSXRay.Segment('annotations'))
const result = handler(event, context, callback)
if (result != null) {
Promise.resolve(result).then(
resolved => {
console.log('Result:')
console.log(JSON.stringify(resolved))
},
rejected => {
console.log('Error:')
console.log(rejected)
}
)
}
})
loopback.createContext = function(scopeName) {
// Make the namespace globally visible via the process.context property
process.context = process.context || {};
var ns = process.context[scopeName];
if (!ns) {
ns = cls.createNamespace(scopeName);
process.context[scopeName] = ns;
// Set up loopback.getCurrentContext()
loopback.getCurrentContext = function() {
return ns && ns.active ? ns : null;
};
chain(juggler);
chain(remoting);
}
return ns;
};
var ns = require('continuation-local-storage').createNamespace('myNameSpace');
require('cls-bluebird')( ns );
// Promise is now patched to maintain CLS context
const assert = require('assert');
const initTracer = require('../../lib/tracing').initTracer;
const request = require('request-promise');
const { Tags, FORMAT_HTTP_HEADERS } = require('opentracing');
function sayHello(helloTo, greeting) {
const span = tracer.startSpan('say-hello');
span.setTag('hello-to', helloTo);
span.setBaggageItem('greeting', greeting)
ns.run( () => {
module.exports = function(sails) {
global['Sequelize'] = require('sequelize');
Sequelize.cls = require('continuation-local-storage').createNamespace('sails-sequelize-postgresql');
return {
initialize: function(next) {
this.initAdapters();
this.initModels();
var connection, migrate, sequelize;
sails.log.verbose('Using connection named ' + sails.config.models.connection);
connection = sails.config.connections[sails.config.models.connection];
if (connection == null) {
throw new Error('Connection \'' + sails.config.models.connection + '\' not found in config/connections');
}
if (connection.options == null) {
connection.options = {};
}
connection.options.logging = sails.log.verbose; //A function that gets executed everytime Sequelize would log something.
static getSession() {
if (PrincipalContext.session != null && PrincipalContext.session != 'undefined') {
//cls = require('continuation-local-storage').getNamespace;
PrincipalContext.session = cls.getNamespace('session');
} else {
console.log('creating session from principal context');
//cls = require('continuation-local-storage').createNamespace;
PrincipalContext.session = cls.createNamespace('session');
}
return PrincipalContext.session;
}
* *
* * This program and the accompanying materials are made available under the
* * terms of the Eclipse Public License v. 2.0 which is available at
* * http://www.eclipse.org/legal/epl-2.0
* *
* * SPDX-License-Identifier: EPL-2.0
* *******************************************************************************
*
*/
const Sequelize = require('sequelize');
const appConfig = require('./../config');
const cls = require('continuation-local-storage');
const logger = require('./../logger');
let namespace = cls.createNamespace('fog-controller-namespace');
Sequelize.useCLS(namespace);
const Op = Sequelize.Op;
const operatorsAliases = {
$eq: Op.eq,
$ne: Op.ne,
$gte: Op.gte,
$gt: Op.gt,
$lte: Op.lte,
$lt: Op.lt,
$not: Op.not,
$in: Op.in,
$notIn: Op.notIn,
$is: Op.is,
$like: Op.like,
enableAutomaticMode: function enableAutomaticMode() {
cls_mode = true;
cls.createNamespace(NAMESPACE);
logger.getLogger().debug('Overriding AWS X-Ray SDK mode. Set to automatic mode.');
},
* @submodule Server
*/
"use strict";
var domain = require('domain');
var __defaults = {};
var package_json = require_core("../package.json");
var config = require_core("server/config");
var app_name = package_json.name;
var USE_CLS = config.use_cls;
var ns;
if (USE_CLS) {
ns = require("continuation-local-storage").createNamespace('superfluous');
}
var __id = 0;
module.exports = function(key, val) {
if (typeof val !== "undefined") {
module.exports.get()[key] = val;
} else {
return module.exports.get()[key];
}
};
var context = module.exports;
_.extend(module.exports, {
/**
* Sets the current context in use
*
Initializer.add('startup', 'stex.cls', ['stex.config'], function(stex) {
var namespaceName = stex.conf.get('cls-namespace') || "org.stellar.stex";
var namespace = createNamespace(namespaceName);
patchBluebird(namespace);
stex.cls = {
get: function(name) {
var namespace = getNamespace(namespaceName);
return namespace.get(name);
},
getNamespace: function () {
return getNamespace(namespaceName);
}
}
});