@@ -2,9 +2,31 @@ let mongoose = require('mongoose')
22const extend = require ( 'util' ) . _extend ;
33mongoose . set ( 'debug' , false ) ;
44let ObjectId = require ( 'mongoose' ) . Types . ObjectId
5-
65const config = require ( 'config' )
76
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+
830let elasticsearch = require ( 'elasticsearch' )
931let rpRequest = require ( 'request-promise' )
1032let http = require ( 'http' )
@@ -13,7 +35,6 @@ let https = require('https')
1335const uuidV1 = require ( 'uuid/v1' ) ;
1436let ESuserData = null
1537let Promise = require ( 'es6-promise' ) . Promise
16- let ObjSchema = mongoose . Schema ;
1738
1839let rethink = require ( 'rethinkdb' )
1940let rethinkDBConnection = extend ( { } , config . get ( 'rethinkDBConnection' ) )
@@ -46,8 +67,9 @@ let activeSummary = []
4667let ESClient = new elasticsearch . Client ( {
4768 host : esUrl ,
4869 requestTimeout : 100000
49- // ,log: 'trace'
70+ // ,log: 'trace'
5071} )
72+ let uploadedRecord = 0
5173
5274let optionsES = {
5375 tls : 'https://' ,
@@ -71,6 +93,7 @@ let fileTypes =
7193
7294let rethinkDbConnectionObj = null
7395let doJob = async function ( objWorkJob , next ) {
96+ finalSKU = [ ]
7497 rethinkDbConnectionObj = await connectRethinkDB ( rethinkDBConnection )
7598 return new Promise ( async ( resolve , reject ) => {
7699 console . log ( '==============In Do Job==============' )
@@ -118,6 +141,10 @@ let doJob = async function (objWorkJob, next) {
118141
119142function updateImportTrackerStatus ( trackerId ) {
120143 return new Promise ( async ( resolve , reject ) => {
144+ if ( uploadedRecord <= 0 ) {
145+ reject ( { "message" :"data not uploaded, record count is zero" } )
146+ }
147+
121148 rethinkDbConnectionObj = await connectRethinkDB ( rethinkDBConnection )
122149 rethink . db ( rethinkDBConnection . db ) . table ( rethinkDBConnection . table )
123150 . filter ( { 'id' : trackerId } )
@@ -196,7 +223,7 @@ async function findVirtualShopData (rconnObj, rdb, rtable, username, userObj) {
196223 return new Promise ( async ( resolve , reject ) => {
197224 console . log ( '================findVal=========' , username )
198225 rethink . db ( rdb ) . table ( rtable )
199- . filter ( { 'esUser' : username } )
226+ . filter ( { 'esUser' : username , 'userType' : 'supplier' } )
200227 . run ( rconnObj , function ( err , cursor ) {
201228 if ( err ) {
202229 reject ( err )
@@ -332,7 +359,7 @@ async function makeNewPreviewUser (objWorkJob) {
332359
333360
334361function 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' } )
336363 let modelOBUsers
337364 let modelName = 'mdlUsers'
338365 if ( mongoose . models && mongoose . models [ modelName ] ) {
@@ -343,7 +370,7 @@ function getUserDataFromMongo(userid) {
343370 let userDataa = modelOBUsers . find ( { '_id' : userid } )
344371 return userDataa
345372}
346-
373+ let finalSKU = [ ]
347374async function userDataPrepared ( objWorkJob ) {
348375 //console.log('ESuserData', ESuserData)
349376 // user data not set throws exception user not exists
@@ -386,7 +413,7 @@ async function userDataPrepared (objWorkJob) {
386413 }
387414 } )
388415}
389- let finalSKU = [ ]
416+
390417async function getUpdateRecords ( objWorkJob , currentProducts , futureProducts ) {
391418 let uploadType = objWorkJob . data . uploadType
392419 let jobData = objWorkJob . data
@@ -506,7 +533,7 @@ let delayPromise = (delay) => {
506533
507534let perPageDataUpload = 100
508535let batchPromise = [ ]
509- let uploadedRecord = 0
536+
510537// to make batch for data upload
511538async function makeBatch ( objWorkJob , listObjects , currentProductsData , makeProductUpdateJsonObj ) {
512539 return new Promise ( async ( resolve , reject ) => {
@@ -1049,7 +1076,7 @@ function getUserNewVersion (ESUser) {
10491076
10501077function makeDynamicCollectionObj ( collectionName ) {
10511078 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 } )
10531080 let modelName = 'mdl' + collectionName
10541081 if ( mongoose . models && mongoose . models [ modelName ] ) {
10551082 return mongoose . models [ modelName ]
@@ -1060,7 +1087,7 @@ function makeDynamicCollectionObj (collectionName) {
10601087
10611088function makeDynamicCollectionObjWithoutPrefix ( collectionName ) {
10621089 // 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 } )
10641091 let modelName = 'mdl' + collectionName
10651092 if ( mongoose . models && mongoose . models [ modelName ] ) {
10661093 return mongoose . models [ modelName ]
@@ -1082,6 +1109,7 @@ async function deleteESData (versionNo, EsUser) {
10821109 ]
10831110 }
10841111 } ,
1112+ "_source" : [ "sku" , "vid" ] ,
10851113 "size" :10000
10861114 }
10871115 await ESClient . search ( {
@@ -1188,7 +1216,7 @@ function convertStringToArray (str, seprater) {
11881216
11891217// to update user job queue process status to import_completed
11901218function 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' } )
11921220 let mdlobjJobMaster = null
11931221 if ( mongoose . models && mongoose . models . objJobMaster ) {
11941222 mdlobjJobMaster = mongoose . models . objJobMaster
0 commit comments