Subversion Repositories SmartDukaan

Rev

Rev 26816 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3893 chandransh 1
'''
2
Created on 25-Oct-2011
3
 
4
@author: Chandranshu
5
'''
6
import logging
3896 chandransh 7
import subprocess
8
 
9
from shop2020.config.client.ConfigClient import ConfigClient
19686 kshitij.so 10
from shop2020.thriftpy.content.ttypes import ContentServiceException, BulkContentUploadResult
11
from shop2020.utils import ContentUploadUtil
35701 amit 12
logging.basicConfig(level=logging.WARNING)
3893 chandransh 13
 
14
class ContentHandler:
15
    '''
16
    classdocs
17
    '''
18
 
19
    def __init__(self):
3896 chandransh 20
        try:
21
            config_client = ConfigClient()
22
            self.scriptPath = config_client.get_property('PUSH_PRICES_TO_PROD_SCRIPT_PATH')
23
        except:
24
            logging.error("Error while connecting to the config server")
25
            self.scriptPath = "/root/code/trunk/runutils/push-content-to-production.sh"
3893 chandransh 26
 
27
    def pushContentToProduction(self, entityId):
28
        """
3896 chandransh 29
        Push the content of one entity to production
3893 chandransh 30
        Parameters:
31
         - entityId
32
        """
26816 amit.gupta 33
        retval = False
3896 chandransh 34
        if retval:
3910 chandransh 35
            raise ContentServiceException(id=1, message="Pushing content to production failed")
3896 chandransh 36
        return True
3893 chandransh 37
 
19686 kshitij.so 38
    def uploadContent(self,bulkContentList):
39
        notUpdated = []
40
        for bulkContentUpload in bulkContentList:
41
            result = ContentUploadUtil.migrate_content(bulkContentUpload)
42
            try:
43
                if not result['updatedExisting'] or result['n']==0:
44
                    obj = BulkContentUploadResult()
45
                    obj.entity_id = bulkContentUpload.new_entity_id
46
                    obj.message = "Not updated, probably due to error in cloning"
47
                    notUpdated.append(obj)
48
            except:
49
                obj = BulkContentUploadResult()
50
                obj.entity_id = bulkContentUpload.new_entity_id
51
                obj.message = "Not updated, probably due to error in cloning"
52
                notUpdated.append(obj)
53
        return notUpdated
54
 
3893 chandransh 55
    def close_session(self):
56
        pass
57
 
58
    def isAlive(self, ):
59
        """
60
        For checking weather service is active alive or not. It also checks connectivity with database
61
        """
62
        try:
63
            return True
64
        except:
65
            return False
66
        finally:
67
            self.close_session()