init
This commit is contained in:
32
web/api/components/data.py
Normal file
32
web/api/components/data.py
Normal file
@@ -0,0 +1,32 @@
|
||||
import json
|
||||
import traceback
|
||||
|
||||
from nc_http.core import Response
|
||||
|
||||
from api.blueprint import data
|
||||
from commons.constants.material_task import MaterialTaskStatus
|
||||
from commons.models.material_task import MaterialTask
|
||||
from commons.services.data import DataService
|
||||
from core.extensions import siwa
|
||||
|
||||
|
||||
@data.route('/task/<int:task_id>/refresh', methods=['GET'])
|
||||
@siwa.doc(tags=[""], summary='')
|
||||
def refresh_task(task_id):
|
||||
with MaterialTask.atomic() as session:
|
||||
data = MaterialTask.get_by_id(task_id, session)
|
||||
if not data:
|
||||
pass
|
||||
data.status = MaterialTaskStatus.DOING
|
||||
session.flush()
|
||||
try:
|
||||
content = DataService.get_content(type=data.type)
|
||||
data.content = json.dumps(content, ensure_ascii=False)
|
||||
data.status = MaterialTaskStatus.DONE
|
||||
session.flush()
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
data.status = MaterialTaskStatus.FAILED
|
||||
session.flush()
|
||||
|
||||
return Response()
|
Reference in New Issue
Block a user