Subversion Repositories SmartDukaan

Rev

Rev 19933 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 19933 Rev 35608
Line 1... Line 1...
1
import pymongo
1
import pymongo
-
 
2
import threading
2
 
3
 
3
local_mongo = None
4
local_mongo = None
-
 
5
_mongo_lock = threading.Lock()
4
 
6
 
5
CATEGORY_MAP = {10018:'Carrying Case',10020:'Screen Guard',10014:'Battery'}
7
CATEGORY_MAP = {10018:'Carrying Case',10020:'Screen Guard',10014:'Battery'}
6
 
8
 
7
def get_mongo_connection(host='localhost', port=27017):
9
def get_mongo_connection(host='localhost', port=27017):
8
    global local_mongo
10
    global local_mongo
9
    if local_mongo is None:
11
    if local_mongo is not None:
-
 
12
        return local_mongo
-
 
13
    with _mongo_lock:
-
 
14
        if local_mongo is None:
10
        print "Establishing connection %s host and port %d" %(host,port)
15
            print "Establishing connection %s host and port %d" %(host,port)
11
        try:
16
            try:
12
            local_mongo = pymongo.MongoClient(host, port)
17
                local_mongo = pymongo.MongoClient(host, port,
-
 
18
                                                   maxPoolSize=50,
-
 
19
                                                   minPoolSize=5,
-
 
20
                                                   maxIdleTimeMS=30000,
-
 
21
                                                   waitQueueTimeoutMS=5000,
-
 
22
                                                   serverSelectionTimeoutMS=5000)
13
        except Exception, e:
23
            except Exception, e:
14
            print e
24
                print e
15
            return None
25
                return None
16
    return local_mongo
26
    return local_mongo
17
 
27
 
18
 
28
 
19
def migrate_content(bulkContentUpload):
29
def migrate_content(bulkContentUpload):
20
    new_entity = list(get_mongo_connection().CONTENT.entity.find({'_id':bulkContentUpload.new_entity_id}))
30
    new_entity = list(get_mongo_connection().CONTENT.entity.find({'_id':bulkContentUpload.new_entity_id}))