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
ProxyUpdateTask.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 dc_db.BaseTask import BaseTask
11 # from dc_db.ProxyNewTask import ProxyNewTask
12 import dc_db.Constants as Constants
13 from dtm.EventObjects import GeneralResponse
14 import app.Utils as Utils # pylint: disable=F0401
15 
16 logger = Utils.MPLogger().getLogger()
17 
18 
19 # # ProxyUpdateTask Class, implements Proxy Update task functionality
20 #
22 
23 
24  # #Class constructor
25  #
26  def __init__(self):
27  super(ProxyUpdateTask, self).__init__()
28 
29 
30  # #make all necessary actions to update Proxies in mysql db
31  #
32  # @param urls list of ProxyUpdate objects
33  # @param queryCallback function for queries execution
34  # @return generalResponse instance of GeneralResponse object
35  def process(self, proxyUpdates, queryCallback):
36  generalResponse = GeneralResponse()
37  for proxyUpdate in proxyUpdates:
38  status = False
39 # if ProxyNewTask.lookProxyInDB(proxyUpdate, queryCallback):
40  if self.updateProxy(proxyUpdate, queryCallback):
41  status = True
42  generalResponse.statuses.append(status)
43  return generalResponse
44 
45 
46  # #Method updateProxy updates proxy record in the db
47  #
48  # @param proxy - incoming proxy object
49  # @param queryCallback ueryCallback function for queries execution
50  # @return bool value, is current updateProxy was successful or wasn't
51  def updateProxy(self, proxyUpdate, queryCallback):
52  ret = False
53 
54  fields, values = Constants.getFieldsValuesTuple(proxyUpdate, Constants.ProxyTableDict)
55  fieldValueString = Constants.createFieldsValuesString(fields, values, Constants.proxyExcludeList)
56  if fieldValueString is not None and fieldValueString != "":
57  PROXY_UPDATE_TEMPLATE = "UPDATE `sites_proxy` SET %s WHERE `Site_Id` = '%s' AND `Host` = '%s'"
58  query = PROXY_UPDATE_TEMPLATE % (fieldValueString, proxyUpdate.siteId, proxyUpdate.host)
59 
60  print query
61  queryCallback(query, Constants.PRIMARY_DB_ID)
62  ret = True
63  return ret
GeneralResponse event object, represents general state response for multipurpose usage.
def updateProxy(self, proxyUpdate, queryCallback)
def process(self, proxyUpdates, queryCallback)