Ron Au commited on
Commit
da30f9b
1 Parent(s): 9328827

refactor(tasks): Group JSON properties by relevance

Browse files
Files changed (2) hide show
  1. app.py +10 -3
  2. static/js/network.js +1 -5
app.py CHANGED
@@ -36,7 +36,7 @@ def get_place_in_queue(task_id):
36
 
37
  def calculate_eta(task_id):
38
  total_durations = list(task["completed_at"] - task["started_at"]
39
- for task in tasks.values() if "completed_at" in task)
40
 
41
  initial_place_in_queue = tasks[task_id]["initial_place_in_queue"]
42
 
@@ -91,10 +91,17 @@ def create_task(background_tasks: BackgroundTasks, new_task: NewTask):
91
 
92
  tasks[task_id] = {
93
  "task_id": task_id,
94
- "created_at": created_at,
95
- "prompt": new_task.prompt,
96
  "status": "queued",
 
 
 
 
 
97
  "poll_count": 0,
 
 
 
 
98
  }
99
 
100
  tasks[task_id]["initial_place_in_queue"] = get_place_in_queue(task_id)
 
36
 
37
  def calculate_eta(task_id):
38
  total_durations = list(task["completed_at"] - task["started_at"]
39
+ for task in tasks.values() if "completed_at" in task and task["status"] == "completed")
40
 
41
  initial_place_in_queue = tasks[task_id]["initial_place_in_queue"]
42
 
 
91
 
92
  tasks[task_id] = {
93
  "task_id": task_id,
 
 
94
  "status": "queued",
95
+ "created_at": created_at,
96
+ "started_at": None,
97
+ "completed_at": None,
98
+ "initial_place_in_queue": None,
99
+ "place_in_queue": None,
100
  "poll_count": 0,
101
+ "last_poll": None,
102
+ "eta": None,
103
+ "prompt": new_task.prompt,
104
+ "value": None,
105
  }
106
 
107
  tasks[task_id]["initial_place_in_queue"] = get_place_in_queue(task_id)
static/js/network.js CHANGED
@@ -36,11 +36,7 @@ const longPollTask = async (task, interval = 5_000, max) => {
36
 
37
  task = await pollTask(task);
38
 
39
- if (task.status === 'completed' || (max && task.poll_count > max)) {
40
- return task;
41
- }
42
-
43
- if (task.status === 'failed') {
44
  return task;
45
  }
46
 
 
36
 
37
  task = await pollTask(task);
38
 
39
+ if (task.status === 'completed' || task.status === 'failed' || (max && task.poll_count > max)) {
 
 
 
 
40
  return task;
41
  }
42