Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ from flask import Flask, render_template, request, jsonify
|
|
| 2 |
from processor import DatasetCommandCenter
|
| 3 |
import threading
|
| 4 |
import uuid
|
|
|
|
| 5 |
|
| 6 |
app = Flask(__name__)
|
| 7 |
jobs = {}
|
|
@@ -33,15 +34,36 @@ def inspect_rows():
|
|
| 33 |
@app.route('/preview', methods=['POST'])
|
| 34 |
def preview():
|
| 35 |
data = request.json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
center = DatasetCommandCenter(token=data.get('token'))
|
|
|
|
| 37 |
try:
|
| 38 |
-
print(data.get('recipe',{}))
|
| 39 |
rows = center.preview_transform(
|
| 40 |
-
data.get('dataset_id'),
|
| 41 |
-
data.get('
|
|
|
|
|
|
|
| 42 |
)
|
|
|
|
|
|
|
| 43 |
return jsonify({"status": "success", "rows": rows})
|
|
|
|
| 44 |
except Exception as e:
|
|
|
|
|
|
|
|
|
|
| 45 |
return jsonify({"status": "error", "message": str(e)})
|
| 46 |
|
| 47 |
@app.route('/execute', methods=['POST'])
|
|
@@ -58,9 +80,9 @@ def execute():
|
|
| 58 |
data.get('target_id'),
|
| 59 |
data.get('recipe', {}),
|
| 60 |
data.get('max_rows'),
|
| 61 |
-
data.get('license')
|
| 62 |
)
|
| 63 |
-
|
| 64 |
def task():
|
| 65 |
try:
|
| 66 |
jobs[job_id] = {"status": "running"}
|
|
@@ -68,11 +90,10 @@ def execute():
|
|
| 68 |
jobs[job_id] = {"status": "completed", "result": res}
|
| 69 |
except Exception as e:
|
| 70 |
jobs[job_id] = {"status": "failed", "error": str(e)}
|
| 71 |
-
|
| 72 |
threading.Thread(target=task).start()
|
| 73 |
return jsonify({"status": "started", "job_id": job_id})
|
| 74 |
|
| 75 |
-
|
| 76 |
@app.route('/status/<job_id>', methods=['GET'])
|
| 77 |
def status(job_id):
|
| 78 |
return jsonify(jobs.get(job_id, {"status": "unknown"}))
|
|
|
|
| 2 |
from processor import DatasetCommandCenter
|
| 3 |
import threading
|
| 4 |
import uuid
|
| 5 |
+
import json
|
| 6 |
|
| 7 |
app = Flask(__name__)
|
| 8 |
jobs = {}
|
|
|
|
| 34 |
@app.route('/preview', methods=['POST'])
|
| 35 |
def preview():
|
| 36 |
data = request.json
|
| 37 |
+
recipe = data.get('recipe', {})
|
| 38 |
+
|
| 39 |
+
# DEBUG LOGGING
|
| 40 |
+
print("="*60)
|
| 41 |
+
print("PREVIEW REQUEST RECEIVED")
|
| 42 |
+
print("="*60)
|
| 43 |
+
print("Dataset:", data.get('dataset_id'))
|
| 44 |
+
print("Config:", data.get('config'))
|
| 45 |
+
print("Split:", data.get('split'))
|
| 46 |
+
print("Recipe:")
|
| 47 |
+
print(json.dumps(recipe, indent=2))
|
| 48 |
+
print("="*60)
|
| 49 |
+
|
| 50 |
center = DatasetCommandCenter(token=data.get('token'))
|
| 51 |
+
|
| 52 |
try:
|
|
|
|
| 53 |
rows = center.preview_transform(
|
| 54 |
+
data.get('dataset_id'),
|
| 55 |
+
data.get('config'),
|
| 56 |
+
data.get('split'),
|
| 57 |
+
recipe
|
| 58 |
)
|
| 59 |
+
|
| 60 |
+
print(f"Preview successful: {len(rows)} rows returned")
|
| 61 |
return jsonify({"status": "success", "rows": rows})
|
| 62 |
+
|
| 63 |
except Exception as e:
|
| 64 |
+
print(f"PREVIEW ERROR: {str(e)}")
|
| 65 |
+
import traceback
|
| 66 |
+
traceback.print_exc()
|
| 67 |
return jsonify({"status": "error", "message": str(e)})
|
| 68 |
|
| 69 |
@app.route('/execute', methods=['POST'])
|
|
|
|
| 80 |
data.get('target_id'),
|
| 81 |
data.get('recipe', {}),
|
| 82 |
data.get('max_rows'),
|
| 83 |
+
data.get('license')
|
| 84 |
)
|
| 85 |
+
|
| 86 |
def task():
|
| 87 |
try:
|
| 88 |
jobs[job_id] = {"status": "running"}
|
|
|
|
| 90 |
jobs[job_id] = {"status": "completed", "result": res}
|
| 91 |
except Exception as e:
|
| 92 |
jobs[job_id] = {"status": "failed", "error": str(e)}
|
| 93 |
+
|
| 94 |
threading.Thread(target=task).start()
|
| 95 |
return jsonify({"status": "started", "job_id": job_id})
|
| 96 |
|
|
|
|
| 97 |
@app.route('/status/<job_id>', methods=['GET'])
|
| 98 |
def status(job_id):
|
| 99 |
return jsonify(jobs.get(job_id, {"status": "unknown"}))
|