def build_and_run(): print "Got called: %s" % (request.data) data = json.loads(request.data) print data if 'code' not in data or 'lang' not in data: return "You should provide both 'code' and 'lang'" code = data['code'] lang = data['lang'] print 'API got called with code: %s in %s' % (code, lang) eu.load_image() result = eu.build_and_run(code, lang) return jsonify(result),
from flask import request import executor_utils as eu @app.route('/') def home(): return "Hello everyone!" @app.route('/build_and_run', methods=['POST']) def build_and_run(): data = request.get_json() if 'code' not in data or 'lang' not in data: return 'You should provide "code" and "lang"' code = data['code'] lang = data['lang'] print("API got called with code: %s in %s" % (code, lang)) result = eu.build_and_run(code, lang) return jsonify(result) if __name__ == '__main__': import sys port = int(sys.argv[1]) eu.load_image() #load docker image app.run(port=port) #run the executor at a specific port
import executor_utils as eu import json from flask import Flask from flask import jsonify from flask import request app = Flask(__name__) @app.route('/') @app.route('/build_and_run', methods=['POST']) def build_and_run(): print("dbug") data = json.loads(request.data) if 'code' not in data or 'lang' not in data: return 'invalid data received, not data or language set' print("dbug") code = data['code'] lang = data['lang'] print('API got called with code %s in %s' % (code, lang)) #return jsonify({'build': 'build from flask', 'run': 'hello from flask'}) result = eu.build_and_run(code, lang) return jsonify(result) if __name__ == '__main__': eu.load_image() app.run(debug=True)
import json from flask import Flask app = Flask(__name__) from flask import jsonify from flask import request import executor_utils as eu @app.route('/build_and_run', methods=['POST']) def build_and_run(): data =request.get_json() if 'code' not in data or 'lang' not in data: return 'You should provide "code" and "lang"' code = data['code'] lang = data['lang'] print("API got called with code: %s in %s" % (code, lang)) result = eu.build_and_run(code, lang) return jsonify(result) if __name__ == '__main__': ##当直接调用executor_server时,__name__ == __main__ # import sys # port = int(sys.argv[1]) eu.load_image() #docker容器起来# app.run(port = port) app.run(debug=True)
from flask import Flask, request, jsonify from executor_utils import build_run, load_image import json app = Flask(__name__) # @app.route("/") # def hell0(): # return "hello?" @app.route("/build_and_run", methods=["POST"]) def build_and_run(): data = json.loads(request.data) if "code" not in data or "language" not in data: return "missing code or language" code = data["code"] language = data["language"] print(code, language) res = build_run(code, language) print(res) return jsonify(res) if __name__ == "__main__": load_image() app.run(debug=True)
from flask import Flask from flask import jsonify from flask import request import executor_utils app = Flask(__name__) @app.route("/build_and_run", methods=["POST"]) def build_and_run(): print "Got called: %s" % (request.data) data = json.loads(request.data) if 'code' not in data or 'lang' not in data: return "You should provide botb 'code' and 'lang'" code = data['code'] lang = data['lang'] print "API got called with code: %s in %s" % (code, lang) result = executor_utils.build_and_run(code, lang) return jsonify(result) if __name__ == "__main__": executor_utils.load_image() app.run(debug=True)
from flask import request import executor_utils as eu # define the route path this method will accept @app.route('/') def hello(): return 'Hello World!' @app.route('/build_and_run_results', methods=['POST']) def build_and_run_results(): data = request.get_json() # print data # print 'hahah' if 'code' not in data or 'lang' not in data: return 'You should provide codes and lang' code = data['code'] lang = data['lang'] # print "API get called with code: %s in %s" %(code, lang) result = eu.build_and_run_results(code, lang) return jsonify(result) # check if this file is not imported in and run in other files # true if the the file is executed inside itself if __name__ == '__main__': # set debug to true to make flask works like nodemon # update when file changes eu.load_image() #load image when server start app.run(debug=True)
import executor_utils as eu app = Flask(__name__) @app.route("/") def hello(): return "Hello World!" @app.route("/exec", methods=["POST"]) def codeExce(): data = request.get_json() #print type(data) print "Recv a request to execute the following" print str(data["codes"]) res = "" langType = str(data["langType"]) codes = str(data["codes"]) tmpdir = eu.mk_tmp_dir() eu.create_code_file(tmpdir, langType, codes) res = eu.container_run(client, langType, tmpdir) eu.rm_tmp_dir(tmpdir) return jsonify(output=res) if __name__ == "__main__": client = docker.from_env() eu.load_image(client) app.run()
from flask import jsonify from flask import request app = Flask(__name__) @app.route("/") def hello(): return "hehe" @app.route("/build_and_run", methods=["POST"]) def build_and_run(): print "get called!" data = json.loads(request.data) if 'code' not in data or 'lang' not in data: return "You should provide both 'code' and 'lang'" code = data['code'] lang = data['lang'] print "API got called with code %s in %s" % (code, lang) result = eu.build_and_run(code, lang) return jsonify(result) if __name__ == "__main__": eu.load_image() if len(sys.argv) <= 1: port = 5000 else: port = int(sys.argv[1]) print "Executor running on %d" % port app.run(port=port, debug=True)
@app.route("/") def hello(): return "Hello World, Junrui! Haha~" @app.route("/build_and_run", methods=["POST"]) def build_and_run(): print "Got called: %s" % (request.data) data = json.loads(request.data) if 'code' not in data or 'lang' not in data: return "You should provid both 'code' and 'lang'" code = data['code'] lang = data['lang'] print "API got called with code: %s in % s" % (code, lang) result = eu.build_and_run(code, lang) return jsonify(result) if __name__ == "__main__": eu.load_image() # load first port = int(sys.argv[1]) # set different running port print "Executor running on: %d" % port app.run(port=port)