2 HCE project, Python bindings, Distributed Tasks Manager application. 3 RTCPreprocessor Class content main functional for preprocessor for realtime crawling. 6 @file RTCPreprocessor.py 7 @author Alex <developers.hce@gmail.com>, Alexander Vybornyh <alexander.hce.cluster@gmail.com> 8 @link: http://hierarchical-cluster-engine.com/ 9 @copyright: Copyright © 2013-2014 IOIX Ukraine 10 @license: http://hierarchical-cluster-engine.com/license/ 27 from cement.core
import foundation
29 APP_NAME =
"RTCPreprocessor" 37 MSG_ERROR_PARSE_CMD_PARAMS =
"Error parse command line parameters." 38 MSG_ERROR_EMPTY_CONFIG_FILE_NAME =
"Config file name is empty." 39 MSG_ERROR_WRONG_CONFIG_FILE_NAME =
"Config file name is wrong" 40 MSG_ERROR_LOAD_APP_CONFIG =
"Error loading application config file." 41 MSG_ERROR_READ_LOG_CONFIG =
"Error read log config file." 44 DRCE_NODE_NUMBER =
"DRCE_NODE_NUMBER" 45 DRCE_NODES_TOTAL =
"DRCE_NODES_TOTAL" 48 ERROR_EMPTY_ENV_VARS = 2
51 PREPROCESSOR_OPTION_LOG =
"log" 55 label = DC_CRAWLER_CONSTS.RTC_PREPROCESSOR_APP_NAME
62 foundation.CementApp.__init__(self)
75 foundation.CementApp.setup(self)
81 foundation.CementApp.run(self)
90 self.
logger.info(APP_CONSTS.LOGGER_DELIMITER_LINE)
113 config = ConfigParser.ConfigParser()
114 config.optionxform = str
116 readOk = config.read(configName)
121 if config.has_section(APP_CONSTS.CONFIG_APPLICATION_SECTION_NAME):
124 except Exception, err:
127 return confLogFileName
136 if isinstance(configName, str)
and len(configName) == 0:
139 logging.config.fileConfig(configName)
144 except Exception, err:
154 self.
logger.info(
"Before id:%s items: %s", str(self.
batch.id), str(len(self.
batch.items)))
156 items = self.
batch.items
159 self.
logger.debug(
"Input items: %s", str(self.
batch.items))
160 self.
logger.debug(
"Splitted items: %s", str(splitted_items))
162 self.
logger.debug(
"Output items: %s", str(self.
batch.items))
166 self.
logger.info(
"After id:%s items: %s", str(self.
batch.id), str(len(self.
batch.items)))
169 return [arr[i::count]
for i
in range(count)]
178 for key
in self.
envVars.keys():
179 if key
in os.environ
and os.environ[key] !=
"":
180 self.
envVars[key] = os.environ[key]
181 self.
logger.debug(
"os.environ[%s]: set to <<%s>>" % (key, self.
envVars[key]))
183 self.
logger.debug(
"os.environ[%s]: not set. Use default value: <<%s>>" % (key, self.
envVars[key]))
192 self.
logger.info(
"The batch possible will be reduced")
195 self.
logger.info(
"The batch will not be reduced")
198 self.
exitCode = APP_CONSTS.EXIT_FAILURE
def __loadAppConfig(self, configName)
load application config file
string MSG_ERROR_LOAD_APP_CONFIG
string MSG_ERROR_EMPTY_CONFIG_FILE_NAME
int ERROR_EMPTY_ENV_VARS
Constans as numeric for exit code.
string MSG_ERROR_READ_LOG_CONFIG
RTCPreprocessor Class content main functional for preprocessor for realtime crawling, class inherits from foundation.CementApp.
string DRCE_NODE_NUMBER
Constans used in class.
string MSG_ERROR_WRONG_CONFIG_FILE_NAME
def __loadLogConfig(self, configName)
load log config file
def __init__(self)
constructor
def split(self, arr, count)
def __initApp(self)
initialize application from config files
def setup(self)
setup application
def varDump(obj, stringify=True, strTypeMaxLen=256, strTypeCutSuffix='...', stringifyType=1, ignoreErrors=False, objectsHash=None, depth=0, indent=2, ensure_ascii=False, maxDepth=10)
def run(self)
run application
def getBatchFromInput(self)
string PREPROCESSOR_OPTION_LOG
Constans used options from config file.