@@ -2,9 +2,31 @@ let mongoose = require('mongoose')
2
2
const extend = require ( 'util' ) . _extend ;
3
3
mongoose . set ( 'debug' , false ) ;
4
4
let ObjectId = require ( 'mongoose' ) . Types . ObjectId
5
-
6
5
const config = require ( 'config' )
7
6
7
+ let mongoDBConnection = config . get ( 'mongoDBConnection' )
8
+
9
+ let mongoURL = mongoDBConnection . URL
10
+ if ( process . env . mongoURL !== undefined && process . env . mongoURL !== '' ) {
11
+ mongoURL = process . env . mongoURL
12
+ }
13
+
14
+ // console.log("==========", mongoURL)
15
+ // `Job` here has essentially the same API as JobCollection on Meteor.
16
+ // In fact, job-collection is built on top of the 'meteor-job' npm package!
17
+ mongoose . Promise = global . Promise
18
+ // Connect to the beerlocker MongoDB
19
+ // mongoose.connect('mongodb://localhost:3001/meteor');
20
+ mongoose . connect ( mongoURL , { autoReconnect : true , bufferMaxEntries : 0 , reconnectInterval : 1000 , poolSize : 5 , reconnectTries : 30 , keepAlive : 800000 , connectTimeoutMS : 800000 } , function ( err , db ) {
21
+ if ( err ) {
22
+ console . log ( 'error.........' , err )
23
+ }
24
+ } )
25
+ // mongoose.connect('mongodb://obdev:123456@ds133311.mlab.com:33311/closeoutpromo');
26
+ let ObjSchema = mongoose . Schema
27
+
28
+
29
+
8
30
let elasticsearch = require ( 'elasticsearch' )
9
31
let rpRequest = require ( 'request-promise' )
10
32
let http = require ( 'http' )
@@ -13,7 +35,6 @@ let https = require('https')
13
35
const uuidV1 = require ( 'uuid/v1' ) ;
14
36
let ESuserData = null
15
37
let Promise = require ( 'es6-promise' ) . Promise
16
- let ObjSchema = mongoose . Schema ;
17
38
18
39
let rethink = require ( 'rethinkdb' )
19
40
let rethinkDBConnection = extend ( { } , config . get ( 'rethinkDBConnection' ) )
@@ -46,8 +67,9 @@ let activeSummary = []
46
67
let ESClient = new elasticsearch . Client ( {
47
68
host : esUrl ,
48
69
requestTimeout : 100000
49
- // ,log: 'trace'
70
+ // ,log: 'trace'
50
71
} )
72
+ let uploadedRecord = 0
51
73
52
74
let optionsES = {
53
75
tls : 'https://' ,
@@ -71,6 +93,7 @@ let fileTypes =
71
93
72
94
let rethinkDbConnectionObj = null
73
95
let doJob = async function ( objWorkJob , next ) {
96
+ finalSKU = [ ]
74
97
rethinkDbConnectionObj = await connectRethinkDB ( rethinkDBConnection )
75
98
return new Promise ( async ( resolve , reject ) => {
76
99
console . log ( '==============In Do Job==============' )
@@ -118,6 +141,10 @@ let doJob = async function (objWorkJob, next) {
118
141
119
142
function updateImportTrackerStatus ( trackerId ) {
120
143
return new Promise ( async ( resolve , reject ) => {
144
+ if ( uploadedRecord <= 0 ) {
145
+ reject ( { "message" :"data not uploaded, record count is zero" } )
146
+ }
147
+
121
148
rethinkDbConnectionObj = await connectRethinkDB ( rethinkDBConnection )
122
149
rethink . db ( rethinkDBConnection . db ) . table ( rethinkDBConnection . table )
123
150
. filter ( { 'id' : trackerId } )
@@ -196,7 +223,7 @@ async function findVirtualShopData (rconnObj, rdb, rtable, username, userObj) {
196
223
return new Promise ( async ( resolve , reject ) => {
197
224
console . log ( '================findVal=========' , username )
198
225
rethink . db ( rdb ) . table ( rtable )
199
- . filter ( { 'esUser' : username } )
226
+ . filter ( { 'esUser' : username , 'userType' : 'supplier' } )
200
227
. run ( rconnObj , function ( err , cursor ) {
201
228
if ( err ) {
202
229
reject ( err )
@@ -332,7 +359,7 @@ async function makeNewPreviewUser (objWorkJob) {
332
359
333
360
334
361
function getUserDataFromMongo ( userid ) {
335
- let ObjMain = new ObjSchema ( { _id : 'string' } , { strict : false , 'collection' : 'users' } )
362
+ let ObjMain = new ObjSchema ( { _id : 'string' } , { strict : false , bufferCommands : false , 'collection' : 'users' } )
336
363
let modelOBUsers
337
364
let modelName = 'mdlUsers'
338
365
if ( mongoose . models && mongoose . models [ modelName ] ) {
@@ -343,7 +370,7 @@ function getUserDataFromMongo(userid) {
343
370
let userDataa = modelOBUsers . find ( { '_id' : userid } )
344
371
return userDataa
345
372
}
346
-
373
+ let finalSKU = [ ]
347
374
async function userDataPrepared ( objWorkJob ) {
348
375
//console.log('ESuserData', ESuserData)
349
376
// user data not set throws exception user not exists
@@ -386,7 +413,7 @@ async function userDataPrepared (objWorkJob) {
386
413
}
387
414
} )
388
415
}
389
- let finalSKU = [ ]
416
+
390
417
async function getUpdateRecords ( objWorkJob , currentProducts , futureProducts ) {
391
418
let uploadType = objWorkJob . data . uploadType
392
419
let jobData = objWorkJob . data
@@ -506,7 +533,7 @@ let delayPromise = (delay) => {
506
533
507
534
let perPageDataUpload = 100
508
535
let batchPromise = [ ]
509
- let uploadedRecord = 0
536
+
510
537
// to make batch for data upload
511
538
async function makeBatch ( objWorkJob , listObjects , currentProductsData , makeProductUpdateJsonObj ) {
512
539
return new Promise ( async ( resolve , reject ) => {
@@ -1049,7 +1076,7 @@ function getUserNewVersion (ESUser) {
1049
1076
1050
1077
function makeDynamicCollectionObj ( collectionName ) {
1051
1078
collectionName = collectionName . charAt ( 0 ) . toUpperCase ( ) + collectionName . slice ( 1 ) . toLowerCase ( )
1052
- let ObjMain = new ObjSchema ( { _id : 'string' } , { strict : false , 'collection' : collectionPrefix + collectionName } )
1079
+ let ObjMain = new ObjSchema ( { _id : 'string' } , { strict : false , bufferCommands : false , 'collection' : collectionPrefix + collectionName } )
1053
1080
let modelName = 'mdl' + collectionName
1054
1081
if ( mongoose . models && mongoose . models [ modelName ] ) {
1055
1082
return mongoose . models [ modelName ]
@@ -1060,7 +1087,7 @@ function makeDynamicCollectionObj (collectionName) {
1060
1087
1061
1088
function makeDynamicCollectionObjWithoutPrefix ( collectionName ) {
1062
1089
// collectionName = collectionName.charAt(0).toUpperCase() + collectionName.slice(1).toLowerCase()
1063
- let ObjMain = new ObjSchema ( { _id : 'string' } , { strict : false , 'collection' : collectionName } )
1090
+ let ObjMain = new ObjSchema ( { _id : 'string' } , { strict : false , bufferCommands : false , 'collection' : collectionName } )
1064
1091
let modelName = 'mdl' + collectionName
1065
1092
if ( mongoose . models && mongoose . models [ modelName ] ) {
1066
1093
return mongoose . models [ modelName ]
@@ -1082,6 +1109,7 @@ async function deleteESData (versionNo, EsUser) {
1082
1109
]
1083
1110
}
1084
1111
} ,
1112
+ "_source" : [ "sku" , "vid" ] ,
1085
1113
"size" :10000
1086
1114
}
1087
1115
await ESClient . search ( {
@@ -1188,7 +1216,7 @@ function convertStringToArray (str, seprater) {
1188
1216
1189
1217
// to update user job queue process status to import_completed
1190
1218
function updateJobQueueStatus ( objWorkJob ) {
1191
- let objJobMaster = new ObjSchema ( { _id : String } , { strict : false , 'collection' : 'uploaderJobMaster' } )
1219
+ let objJobMaster = new ObjSchema ( { _id : String } , { strict : false , bufferCommands : false , 'collection' : 'uploaderJobMaster' } )
1192
1220
let mdlobjJobMaster = null
1193
1221
if ( mongoose . models && mongoose . models . objJobMaster ) {
1194
1222
mdlobjJobMaster = mongoose . models . objJobMaster
0 commit comments