HCE Project Python language Distributed Tasks Manager Application, Distributed Crawler Application and client API bindings.  2.0.0-chaika
Hierarchical Cluster Engine Python language binding
AttrUpdateTask.py
Go to the documentation of this file.
1 '''
2 @package: dc
3 @author scorp
4 @link: http://hierarchical-cluster-engine.com/
5 @copyright: Copyright © 2013-2014 IOIX Ukraine
6 @license: http://hierarchical-cluster-engine.com/license/
7 @since: 0.1
8 '''
9 
10 from dtm.EventObjects import GeneralResponse
11 from dc_db.BaseTask import BaseTask
12 from dc_db.AttrSetTask import AttrSetTask
13 import dc_db.Constants as Constants
14 import dc.EventObjects
15 import app.Utils as Utils # pylint: disable=F0401
16 
17 logger = Utils.MPLogger().getLogger()
18 
19 
20 # # AttrSetTask Class, implements AttributeSet task functionality
21 #
23 
24 
25  # #Class constructor
26  #
27  def __init__(self):
28  super(AttrUpdateTask, self).__init__()
30 
31 
32  # #make all necessary actions to get update attributes data in db
33  #
34  # @param attrUpdates list of AttributeUpdate objects
35  # @param queryCallback function for queries execution
36  # @return generalResponse instance of GeneralResponse object
37  def process(self, attrUpdates, queryCallback):
38  ret = GeneralResponse()
39  for attrUpdate in attrUpdates:
40  statusValue = False
41  if self.isSiteExist(attrUpdate.siteId, queryCallback):
42  if self.arrtSet.selectAttribute(attrUpdate, queryCallback):
43  self.updateAttribute(attrUpdate, queryCallback)
44  statusValue = True
45  else:
46  localAttribute = dc.EventObjects.Attribute(attrUpdate.siteId, attrUpdate.name)
47  localAttribute.urlMd5 = attrUpdate.urlMd5 if attrUpdate.urlMd5 is not None else ""
48  localAttribute.value = attrUpdate.value if attrUpdate.value is not None else ""
49  localRet = self.arrtSet.process([localAttribute], queryCallback)
50  if len(localRet.statuses) > 0 and localRet.statuses[0] == AttrSetTask.CODE_GOOD_INSERT:
51  statusValue = True
52  ret.statuses.append(statusValue)
53  return ret
54 
55 
56  # # Update already exists attributes
57  #
58  # @param attrObject instance of Attribute object
59  # @param queryCallback function for queries execution
60  def updateAttribute(self, attrObject, queryCallback):
61  UPDATE_TEMPLATE = "UPDATE `att_%s` SET `Value` = '%s' WHERE `Name` = '%s' AND `URLMd5` = '%s'"
62  query = UPDATE_TEMPLATE % (attrObject.siteId, Utils.escape(attrObject.value), attrObject.name,
63  attrObject.urlMd5 if attrObject.urlMd5 is not None else "")
64  queryCallback(query, Constants.ATT_DB_ID, Constants.EXEC_NAME, True)
def isSiteExist(self, siteId, queryCallback, userId=None)
Definition: BaseTask.py:29
GeneralResponse event object, represents general state response for multipurpose usage.
def process(self, attrUpdates, queryCallback)
def updateAttribute(self, attrObject, queryCallback)