Browse Source

update db connection for cron task

Jérôme BUISINE 1 year ago
parent
commit
1e27d8d6cc
3 changed files with 13 additions and 3 deletions
  1. 2 1
      back.Dockerfile
  2. 10 1
      expeStats.js
  3. 1 1
      utils/extract_experiment.py

+ 2 - 1
back.Dockerfile

@@ -9,8 +9,9 @@ WORKDIR /usr/src/app
 EXPOSE 5000
 
 # Install python
-RUN apk add --update --no-cache python python-dev py-pip
+RUN apk add --update --no-cache gcc gfortran python python-dev py-pip build-base wget freetype-dev libpng-dev openblas-dev
 RUN pip install pymongo
+RUN pip install numpy
 
 # Install dependencies and generate documentation
 RUN yarn install && yarn doc

+ 10 - 1
expeStats.js

@@ -2,12 +2,19 @@
 
 // import { experiments } from './experimentConfig'
 const config = require('./experimentConfig')
-
+const mongoose = require('mongoose')
+const configApp = require('./config')
+const mongoDatabaseURI = configApp.mongoDatabaseURI
 const fs = require('fs-extra')
 
 const winston = require('winston')
 const execSync = require('child_process').execSync
 
+// const connectDb = async () => {
+//   await mongoose.connect(mongoDatabaseURI, { useNewUrlParser: true, useFindAndModify: false })
+//   mongoose.connection.on('error', (err) => console.log(err))
+// }
+
 // get whitelist scene for MatchExtractsWithReference experiment
 const scenes = config.experiments.MatchExtractsWithReference.availableScenes.whitelist
 
@@ -28,6 +35,8 @@ const fileLogger = winston.createLogger({
 })
 
 const setup = async (logToFile = false) => {
+  // await connectDb()
+
   if (logToFile) fileLogger.info({ log: 'Start extraction of data from mongo for `MatchExtractsExperiments`.', date: new Date() })
 
   execSync('python utils/extract_experiment.py', { encoding: 'utf-8' })

+ 1 - 1
utils/extract_experiment.py

@@ -2,7 +2,7 @@
 from pymongo import MongoClient
 import json, os
 
-connection = MongoClient()
+connection = MongoClient('mongodb://mongo:27017')
 
 db = connection['sin3d']
 data_collection = db['datas']