def invoke(handler, params): if not handler.connection.db.projects.find_one({'name': params['name']}): raise TotoException(ERROR_INVALID_PROJECT, "No project exists with that name.") values = dict([[k, params[k]] for k in ARGS]) values['story_progress'] /= 100.0 values['project_progress'] /= 100.0 values['timestamp'] = time() handler.connection.db.updates.insert(values) EventManager.instance().send("project_updated", {'name': params['name']}) return view.invoke(handler, {'name': params['name']})
def main_loop(self): db_connection = configured_connection() application_settings = {} if options.cookie_secret: application_settings['cookie_secret'] = options.cookie_secret if options.autoreload: application_settings['debug'] = True handlers = [] if options.use_web_sockets: handlers.append(('%s/?([^/]?[\w\./]*)' % os.path.join(options.root, options.socket_path), TotoSocketHandler, { 'db_connection': db_connection })) if options.client_side_worker_path: handlers.append((os.path.join(options.root, options.client_side_worker_path), ClientSideWorkerSocketHandler)) if not options.event_mode == 'off': from toto.events import EventManager event_manager = EventManager.instance() event_manager.address = 'tcp://*:%s' % (options.event_port + self.service_id) event_manager.start_listening() for i in xrange(process_count()): event_manager.register_server('tcp://127.0.0.1:%s' % (options.event_port + i)) if options.remote_event_receivers: for address in options.remote_event_receivers: event_manager.register_server(address) init_module = self.__event_init if init_module: init_module.invoke(event_manager) if not options.event_mode == 'only': handlers.append(('%s/?([^/]?[\w\./]*)' % options.root.rstrip('/'), TotoHandler, { 'db_connection': db_connection })) application = Application(handlers, **application_settings) if options.startup_function: startup_path = options.startup_function.rsplit('.') __import__(startup_path[0]).__dict__[startup_path[1]]( db_connection=db_connection, application=application) server = HTTPServer(application) server.add_sockets(self.__pending_sockets) print "Starting server %d on port %s" % (self.service_id, options.port) IOLoop.instance().start()
def main_loop(self): db_connection = configured_connection() if options.remote_event_receivers: from toto.events import EventManager event_manager = EventManager.instance() if options.remote_instances: for address in options.remote_event_receivers.split(','): event_manager.register_server(address) init_module = self.__event_init if init_module: init_module.invoke(event_manager) serialization = options.serialization_module and __import__(options.serialization_module) or pickle compression = options.compression_module and __import__(options.compression_module) worker = TotoWorker(self.__method_module, options.worker_socket_address, db_connection, compression, serialization) if options.startup_function: startup_path = options.startup_function.rsplit('.') __import__(startup_path[0]).__dict__[startup_path[1]](worker=worker, db_connection=db_connection) worker.start()
def main_loop(self): db_connection = configured_connection() application_settings = {} if options.cookie_secret: application_settings['cookie_secret'] = options.cookie_secret if options.autoreload: application_settings['debug'] = True handlers = [] if options.use_web_sockets: handlers.append(('%s/?([^/]?[\w\./]*)' % os.path.join(options.root, options.socket_path), TotoSocketHandler, {'db_connection': db_connection})) if options.client_side_worker_path: handlers.append((os.path.join(options.root, options.client_side_worker_path), ClientSideWorkerSocketHandler)) if not options.event_mode == 'off': from toto.events import EventManager event_manager = EventManager.instance() event_manager.address = 'tcp://*:%s' % (options.event_port + self.service_id) event_manager.start_listening() for i in xrange(process_count()): event_manager.register_server('tcp://127.0.0.1:%s' % (options.event_port + i)) if options.remote_event_receivers: for address in options.remote_event_receivers: event_manager.register_server(address) init_module = self.__event_init if init_module: init_module.invoke(event_manager) if not options.event_mode == 'only': handlers.append(('%s/?([^/]?[\w\./]*)' % options.root.rstrip('/'), TotoHandler, {'db_connection': db_connection})) application = Application(handlers, **application_settings) if options.startup_function: startup_path = options.startup_function.rsplit('.') __import__(startup_path[0]).__dict__[startup_path[1]](db_connection=db_connection, application=application) server = HTTPServer(application) server.add_sockets(self.__pending_sockets) print "Starting server %d on port %s" % (self.service_id, options.port) IOLoop.instance().start()
def main_loop(self): db_connection = configured_connection() if options.remote_event_receivers: from toto.events import EventManager event_manager = EventManager.instance() if options.remote_instances: for address in options.remote_event_receivers.split(','): event_manager.register_server(address) init_module = self.__event_init if init_module: init_module.invoke(event_manager) serialization = options.serialization_module and __import__( options.serialization_module) or pickle compression = options.compression_module and __import__( options.compression_module) worker = TotoWorker(self.__method_module, options.worker_socket_address, db_connection, compression, serialization) if options.startup_function: startup_path = options.startup_function.rsplit('.') __import__(startup_path[0]).__dict__[startup_path[1]]( worker=worker, db_connection=db_connection) worker.start()
def invoke(handler, params): EventManager.instance().send("message", params["message"]) return "message sent!"
def invoke(handler, params): handler.connection.db.projects.remove({'name': params['name']}) handler.connection.db.updates.remove({'name': params['name']}) EventManager.instance().send("project_updated", {'name': params['name']}) return {'name': params['name']}
def invoke(handler, params): if handler.connection.db.projects.find_one({'name': params['name']}): raise TotoException(ERROR_PROJECT_EXISTS, "A project with that name already exists") handler.connection.db.projects.insert({'name': params['name'], 'client': params['client'], 'hidden': False}) EventManager.instance().send("project_updated", {'name': params['name']}) return params;
def invoke(handler, params): def project_updated(project): handler.respond(result=project) EventManager.instance().register_handler("project_updated", project_updated)