-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
34 lines (27 loc) · 1 KB
/
Copy pathmain.py
File metadata and controls
34 lines (27 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from flask import Flask, json, jsonify, render_template
from tasks import apiworld
app = Flask(__name__)
from celery_config import celery_app
celery_app.autodiscover_tasks(['tasks'], force=True)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/apiworld')
def apiworld_route():
task = apiworld.delay()
print('Task Launched!')
return jsonify({"success": True, "task_id": task.id})
@app.route('/check_task/<task_id>', methods=['GET'])
def check_task(task_id):
task = celery_app.AsyncResult(task_id)
print(f"Task {task_id} is currently in state: {task.state}") # Print the task state
if task.state == 'SUCCESS':
# Assuming the task returns filename upon success
response = jsonify({"status": "SUCCESS", "filename": task.result})
return response
elif task.state == 'PENDING':
return jsonify({"status": "PENDING"})
else:
return jsonify({"status": task.state})
if __name__ == '__main__':
app.run(debug=True)