def put(self): allowed_routes = ['{{ function_name }}'] function = self.request.get('f') input_source = self.request.get('input1') json_data = {'f':function, 'input1':input_source} output = '' if self.request.get('output') == '': key_length = 16 # for now, randomly generates keys 16 chars long json_data['output'] = base64.b64encode(os.urandom(key_length)) # TODO - does this work in app engine? else: json_data['output'] = str(self.request.get('output')) output = str(json_data['output']) if function in allowed_routes: url = '/' + function logging.debug('starting a request for url ' + url) queue.put_message(get_queue('tasks'), json.dumps(json_data)) key_length = 16 task_name = base64.b64encode(os.urandom(key_length)) result = {'result':'success', 'task_id':task_name, 'output':output, 'id':task_name} logging.debug('result of job with input data' + str(json_data) + ' was ' + str(result)) self.response.out.write(json.dumps(result)) else: reason = 'Cannot add a task for function type ' + str(function) result ={'result':'failure', 'reason':reason} self.response.out.write(json.dumps(result))
def put(self): allowed_functions = ["{{ function_name }}"] function = self.request.get("function") or self.request.get("f") key_length = 16 id = self.request.get("id") if not id: id = base64.b64encode(os.urandom(key_length), "-_") output_location = self.request.get("output_location") or self.request.get("output") if not output_location: output_location = base64.b64encode(os.urandom(key_length), "-_") logging.info("Posting task " + id + " for function " + function) if function in allowed_functions: queue.put_message( get_queue("tasks"), json.dumps({"function": function, "id": id, "output_location": output_location}) ) result = {"result": "success", "id": id, "output_location": output_location} self.response.out.write(json.dumps(result)) else: reason = "Cannot add a task for function type " + str(function) result = {"result": "failure", "reason": reason} self.response.out.write(json.dumps(result))