args: job_id: id of the remote job response: log: newest `LINE_NUM` lines of the log file
()
| 33 | 'GET', |
| 34 | ]) |
| 35 | def get_log(): |
| 36 | ''' |
| 37 | args: |
| 38 | job_id: id of the remote job |
| 39 | response: |
| 40 | log: newest `LINE_NUM` lines of the log file |
| 41 | ''' |
| 42 | try: |
| 43 | job_id = request.args['job_id'] |
| 44 | except: |
| 45 | return make_response( |
| 46 | jsonify(message="No job_id provided, please check your request."), |
| 47 | 400) |
| 48 | |
| 49 | log_dir = current_app.config.get('LOG_DIR') |
| 50 | log_dir = os.path.expanduser(log_dir) |
| 51 | log_file_path = os.path.join(log_dir, job_id, 'stdout.log') |
| 52 | if not os.path.isfile(log_file_path): |
| 53 | return make_response( |
| 54 | jsonify(message="Log not exsits, please check your job_id"), 400) |
| 55 | else: |
| 56 | line_num = current_app.config.get('LINE_NUM') |
| 57 | linecache.checkcache(log_file_path) |
| 58 | log_content = ''.join(linecache.getlines(log_file_path)[-line_num:]) |
| 59 | return make_response( |
| 60 | jsonify(message="Log exsits, content in log", log=log_content), |
| 61 | 200) |
| 62 | |
| 63 | |
| 64 | @app.route( |