コード例 #1
0
ファイル: tabzilla.py プロジェクト: alexbuz/TabZilla
	def runWorker(self, w):
		#clr.AddReferenceByName('Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c')                
		#pprint(w)
		#pprint(self._workers)
		#pprint(self._pipeline_meta)
		from lib.worker import Worker 
		wo = Worker(self._environment,self._logger)
		#pprint(sorted(w['node'].keys()))
		for subworker_id in sorted(w['node'].keys()):
			#worker_type=w['node'].keys()[0]
			#rx = re.compile( r'(\d+)')		
			#short_t = rx.sub( '', subworker_type).strip('_')
			#print short_t
			subworker_type= w['node'][subworker_id]['type']
			confirm(self._pipeline_meta['worker'].has_key(subworker_type),"Specified worker type <%s> is not listed in pipeline meta." % subworker_type)
			confirm(self._workers.has_key(subworker_type),"Specified worker type <%s> is not defined in pipeline workers." % subworker_type)
			subworker_name=w['node'][subworker_id]['node'].keys()[0]
			print subworker_name
			confirm(self._pipeline_meta['worker'][subworker_type].has_key(subworker_name),"Specified worker <%s> of type <%s> is not defined in pipeline meta." % (subworker_name,subworker_type))
			subworker_attr=self._pipeline_meta['worker'][subworker_type][subworker_name]['attr']
			subworker_key='%s.%s' % (subworker_attr['module_name'],subworker_attr['name'])
			#pprint((self._workers[worker_type]));
			#pprint(worker_attr)
			confirm(self._workers[subworker_type].has_key(subworker_key),
					"Specified worker <%s> of type <%s> is not defined in pipeline workers." % (subworker_key,subworker_type))
			subworker_obj = self._workers[subworker_type][subworker_key]
			confirm( not type(subworker_obj) is 'instance', 'Worker object <%s> is not set.' % subworker_key)
		#print worker_obj.__module__
			subwo = copy.copy(subworker_obj)
			#pprint(subwo)
			#sys.exit(1)
			#set etl_object
			etl_object = w['node'][subworker_id]['node'][subworker_attr['name']]
			etl_object['name']=w['attr']['name']
			#pprint(self._environment._pipeline_flags)
			subwo._etl_object=etl_object
			wo.add(subwo)
		#print type(wo)
		#pprint(w)
		wo.set(w)
		#pprint(wo._pp)
		#print 'params: ', wo._pp
		#pprint(dir(wo._pp))
		#sys.exit(1)
		#if not int(self._environment._pipeline_flags.release):
		ft =wo.get_p('FLOW_TYPE', 'ASYNC')
		if ft=='ASYNC':
			wo.start()
		else:
			if ft=='SYNC':
				wo.run()
			else:
				self._logger.error('Unknown FLOW_TYPE %s.' % ft)
コード例 #2
0
ファイル: winwin0.py プロジェクト: HeathKang/ziyan_dam
def main():
    """ main """

    appname = "winwin"

    parser = get_option_parser(appname)
    options, args = parser.parse_args()

    conf_file = os.path.abspath(options.config)

    conf = get_conf(conf_file)

    setup_logger(conf['logging'])

    log.debug("start...")

    worker = Worker(conf)

    worker.run()
コード例 #3
0
class Controller(object):
	NEED_EXIT = False
	SIGNAL_HANDLE = None

	def __init__(self, func, data):
		if not Controller.SIGNAL_HANDLE:
			Controller.signal_init()
			Controller.SIGNAL_HANDLE = Controller.interrupt_handler
		self.cmdMgr = GetCmdMgr()
		self.worker = Worker(func, data)
		self.worker.set_checkFunc(self.get_state)

	def get_state(self):
		return Controller.NEED_EXIT

	def run_cmd(self, cmd):
		func = self.cmdMgr.get_cmd(cmd[0])
		if not func:
			print('Invalid command')
			return
		if self.cmdMgr.is_builtin_cmd(cmd[0]):
			Execute(func, cmd[1:], None)
		else:
			self.worker.run(func, cmd[1:])

	def get_output(self):
		pass

	@classmethod
	def interrupt_handler(cls, signum, frame):
		cls.NEED_EXIT = True

	@classmethod
	def signal_init(cls):
		signal.signal(signal.SIGINT, cls.interrupt_handler)
		signal.signal(signal.SIGTERM, cls.interrupt_handler)