-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathqueue_manager.py
56 lines (45 loc) · 1.76 KB
/
queue_manager.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""
GEEST Plugin
Author: Your Name
Copyright: 2024, Your Organization
License: GPL-3.0-only
This file is part of the GEEST QGIS Plugin. It is available under the terms of the GNU General Public License v3.0 only.
See the LICENSE file in the project root for more information.
"""
from qgis.core import QgsApplication
from .task import GEESTTask
class QueueManager:
"""
Manages the queue of tasks for processing GEEST nodes.
"""
def __init__(self, nodes, model, progress_callback):
self.nodes = nodes
self.model = model
self.progress_callback = progress_callback
self.tasks = []
self.completed_tasks = 0
def generate_tasks(self):
for node in self.nodes:
task = GEESTTask(f"Processing {node['name']}", node)
task.finished.connect(self.on_task_finished)
task.error.connect(self.on_task_error)
self.tasks.append(task)
def process_tasks(self):
self.generate_tasks()
for task in self.tasks:
self.model.update_node_status(task.node, "running")
QgsApplication.taskManager().addTask(task)
def cancel_tasks(self):
for task in self.tasks:
if not task.isCanceled():
task.cancel()
self.model.update_node_status(task.node, "idle")
def on_task_finished(self, result):
self.completed_tasks += 1
status = "success" if result else "error"
self.model.update_node_status(self.sender().node, status)
self.progress_callback(self.completed_tasks, len(self.tasks))
def on_task_error(self):
self.completed_tasks += 1
self.model.update_node_status(self.sender().node, "error")
self.progress_callback(self.completed_tasks, len(self.tasks))