playov2-js-utilities 0.3.38 → 0.3.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/db.connection.js +33 -0
- package/lib/index.js +2 -1
- package/lib/taskscheduler/index.js +3 -0
- package/package.json +1 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
mongoose.Promise = global.Promise;
|
|
3
|
+
const MONGO_CONNECTION = process.env.MONGO_URL || 'mongodb://localhost/playoV2DB'
|
|
4
|
+
const Logger = require("./logger");
|
|
5
|
+
const mongoOptions = {
|
|
6
|
+
reconnectInterval: 500, // Reconnect every 500ms
|
|
7
|
+
connectTimeoutMS: 10000, // Give up initial connection after 10 seconds
|
|
8
|
+
socketTimeoutMS: 45000, // Close sockets after 45 seconds of inactivity
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
var dbConnection;
|
|
12
|
+
|
|
13
|
+
const connectToDB = () => {
|
|
14
|
+
mongoose.connect(MONGO_CONNECTION, mongoOptions, (err, db) => {
|
|
15
|
+
if (err)
|
|
16
|
+
Logger.prepareErrorLog("", err.stack, "Error in connecting to DB")
|
|
17
|
+
else {
|
|
18
|
+
Logger.prepareInfoLog("", {}, "connected to playoV2DB")
|
|
19
|
+
|
|
20
|
+
dbConnection = db;
|
|
21
|
+
return dbConnection;
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const getDb = () => {
|
|
27
|
+
return dbConnection;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports = {
|
|
31
|
+
connectToDB,
|
|
32
|
+
getDb
|
|
33
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -13,5 +13,6 @@ module.exports = {
|
|
|
13
13
|
MessagePublisher: require('./message_publisher'),
|
|
14
14
|
middleware: require('./middleware'),
|
|
15
15
|
taskScheduler: require('./taskscheduler'),
|
|
16
|
-
Models: require('./models')
|
|
16
|
+
Models: require('./models'),
|
|
17
|
+
Db_Connection : require('./db.connection')
|
|
17
18
|
};
|
|
@@ -39,8 +39,11 @@ const saveFutureTask = async (queueId, taskId, payload, eta, count = MAX_RETRY_C
|
|
|
39
39
|
throw CTException('eta can not be before 30 days from now. Schedule directly!', 'ValidationException')
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
const { url, httpMethod } = payload;
|
|
42
43
|
const taskData = {
|
|
43
44
|
taskId,
|
|
45
|
+
url,
|
|
46
|
+
httpMethod,
|
|
44
47
|
payload,
|
|
45
48
|
queueId,
|
|
46
49
|
activationTime: eta,
|