def post(self): """ Get the data from the client and send it out. Give response about getting the data immediately, messages are sent asynchronously """ # check api key api_key = self.get_argument('api_key', None) if api_key not in self.application.storage.api_keys: raise HTTPError(403, 'Access denied') # get the channel and message try: data = json.loads(self.request.body) except: raise HTTPError(400, 'Wrong json data') channel = data.get('channel', None) data = data.get('data', None) if channel is None: raise HTTPError(400, 'No channel specified') if data is None: raise HTTPError(400, 'No data specified') # send out data ioloop.IOLoop.instance().add_callback(self.broadcast, channel, data) logger.info( '[%s] New message from %s' % (channel, self.request.remote_ip) ) # return json response self.write('{"status": "accepted"}') self.finish()
def main(): tornado.options.parse_command_line() app = Application() app.listen(options.port) logger.info('Starting Aqueduct on %d port' % options.port) tornado.ioloop.PeriodicCallback(app.send_waiting, options.interval).start() tornado.ioloop.IOLoop.instance().start()
def get_storage(self): """ Function to configure the storage, currently used only MemoryStorage """ storage_dict = { 'memory': MemoryStorage } storage_type = self.config.get('storage', 'memory') obj = storage_dict[storage_type] logger.info('Storage initialization done. Using %s mode' % storage_type) return obj(self.config)