yeq6x commited on
Commit
3fcb571
1 Parent(s): d859980

get_tasks modified

Browse files
Files changed (1) hide show
  1. app.py +14 -7
app.py CHANGED
@@ -244,13 +244,20 @@ def task_status(task_id):
244
  return jsonify({'error': str(e)}), 500
245
 
246
  def get_active_task_order(task_id):
247
- processing_task_ids = [tid for tid, task in active_tasks.items() if task.is_processing]
248
- non_processing_task_ids = [tid for tid, task in active_tasks.items() if not task.is_processing]
249
- if len(processing_task_ids) == 0:
250
- task_order = 0
251
- else:
252
- task_order = non_processing_task_ids.index(task_id) + 1
253
- return task_order
 
 
 
 
 
 
 
254
 
255
  # get_task_orderイベントハンドラー
256
  @app.route('/get_task_order/<task_id>', methods=['GET'])
 
244
  return jsonify({'error': str(e)}), 500
245
 
246
  def get_active_task_order(task_id):
247
+ try:
248
+ if task_id not in active_tasks.keys():
249
+ return 0
250
+ if active_tasks[task_id].is_processing:
251
+ return 0
252
+ processing_task_ids = [tid for tid, task in active_tasks.items() if task.is_processing]
253
+ non_processing_task_ids = [tid for tid, task in active_tasks.items() if not task.is_processing]
254
+ if len(processing_task_ids) == 0:
255
+ task_order = 0
256
+ else:
257
+ task_order = non_processing_task_ids.index(task_id) + 1
258
+ return task_order
259
+ except Exception as e:
260
+ print(f"Error getting task order: {str(e)}")
261
 
262
  # get_task_orderイベントハンドラー
263
  @app.route('/get_task_order/<task_id>', methods=['GET'])