Initial commit
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
const leaderboards = require("../Data/leaderboard");
|
||||
|
||||
const BATCH_SIZE = 1000;
|
||||
const INTERVAL_TIME = 10000;
|
||||
|
||||
const playerBehaviourContext = global.playerBehaviourContext;
|
||||
let mongoBehaviourCollection = null;
|
||||
let mongoDB = null;
|
||||
|
||||
const { MongoClient } = require("mongodb");
|
||||
async function connect() {
|
||||
const client = new MongoClient("mongodb://localhost:27017");
|
||||
await client.connect({
|
||||
maxPoolSize: 100,
|
||||
minPoolSize: 20,
|
||||
maxConnecting: 20,
|
||||
waitQueueTimeoutMS: 0,
|
||||
socketTimeoutMS: 30000,
|
||||
connectTimeoutMS: 10000,
|
||||
retryWrites: false,
|
||||
directConnection: true
|
||||
});
|
||||
|
||||
return client.db("test");
|
||||
};
|
||||
|
||||
(async function() {
|
||||
mongoDB = await connect();
|
||||
mongoBehaviourCollection = mongoDB.collection("Behaviour");
|
||||
})();
|
||||
|
||||
async function behaviourLoop() {
|
||||
if (playerBehaviourContext.length === 0) return;
|
||||
//require("../Miscellaneous/winston").error(playerBehaviourContext);
|
||||
// console.info(playerBehaviourContext, "loop");
|
||||
const playerBehaviourContextCopy = playerBehaviourContext.slice();
|
||||
|
||||
mongoBehaviourCollection.insertMany(playerBehaviourContextCopy, {
|
||||
ordered: false,
|
||||
writeConcern: { w: 0 },
|
||||
bypassDocumentValidation: true
|
||||
});
|
||||
|
||||
playerBehaviourContext.length = 0;
|
||||
};
|
||||
|
||||
setInterval(behaviourLoop, INTERVAL_TIME);
|
||||
|
||||
module.exports = behaviourLoop;
|
||||
Reference in New Issue
Block a user