def server_heart_beat(self): self.__heart_beat += 1 if self.innerProtocol: if getattr(self.innerProtocol, 'makeTasklet', None): t = self.innerProtocol().makeTasklet(0, None, None) if getattr(t, 'on_server_heart_beat', None): TaskManager.add_task(t.on_server_heart_beat) TaskManager.add_simple_task(Context.Configure.reload)
def main(): if sys.argv[1] not in ('game', 'sdk', 'shell'): raise Exception('game, sdk or shell please !!!') service_type = sys.argv[1] params = parse_cmd_lines() if params.get('help'): useage() else: get_user_name(params) tasks = [] if 'service_file' in params: tasks.append('load_server') tasks.append('log_conf') tasks.append('copy_file') tasks.append('build_shell') tasks.append('load_config') tasks.append('init_context') tasks.append('load_lua') tasks.append('make_end') action = params.get('action') if action == 'start': tasks.append('stop') tasks.append('push_config') if service_type == 'game': tasks.append('make_clear') tasks.append('start') elif service_type == 'sdk': tasks.append('start') elif service_type == 'shell': tasks.append('start') elif action == 'stop': tasks.append('stop') if not tasks: useage() else: Log.log('begin start') Log.log('=================================================') for step, task in enumerate(tasks, 1): Log.log('---------%2s/%s: %s_%s' % (step, len(tasks), service_type, task)) func = None exec 'from task.task_%s import %s_%s as func' % ( task, service_type, task) if func(params): raise Exception('start failed !!!') Log.log('=================================================') Log.log('start done') TaskManager.add_simple_task(TaskManager.end_loop)
def start(self): Context.Log.info('service starting ...') Context.Log.info('InitParams log file =', self.log_path) Context.Log.info('InitParams proc key =', self.proc_key) Context.Log.info('InitParams redis host =', self.redis_host) Context.Log.info('InitParams redis port =', self.redis_port) Context.Log.info('InitParams redis db =', self.redis_db) Context.Log.info('InitParams listen port =', self.listen_port) Context.Log.info('InitParams server id =', self.server_id) Context.Log.info('InitParams tcpProtocol =', self.innerProtocol) Context.Log.info('InitParams udpProtocol =', self.outerProtocol) Context.Log.info('InitParams httpFactory =', self.httpFactory) Context.Log.info('init tasklet startup ...') try: TaskManager.add_simple_task(self.start_up) TaskManager.start_loop() Context.Log.info('service stop ...') except Exception, e: Context.Log.exception()
def do_notice(self, led, end): TaskManager.add_simple_task(self._do_notice, led, end)
tasks.append('make_clear') tasks.append('start') elif service_type == 'sdk': tasks.append('start') elif service_type == 'shell': tasks.append('start') elif action == 'stop': tasks.append('stop') if not tasks: useage() else: Log.log('begin start') Log.log('=================================================') for step, task in enumerate(tasks, 1): Log.log('---------%2s/%s: %s_%s' % (step, len(tasks), service_type, task)) func = None exec 'from task.task_%s import %s_%s as func' % ( task, service_type, task) if func(params): raise Exception('start failed !!!') Log.log('=================================================') Log.log('start done') TaskManager.add_simple_task(TaskManager.end_loop) if __name__ == '__main__': TaskManager.add_simple_task(main) TaskManager.start_loop()