File size: 1,186 Bytes
ef4c8c3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""

Progress.py: Thread-safe progress tracking for dataset generation jobs.

"""
import threading

class ProgressTracker:
    def __init__(self):
        self._progress = {}
        self._lock = threading.Lock()

    def start_job(self, job_id, total_steps):
        with self._lock:
            self._progress[job_id] = {
                "current": 0,
                "total": total_steps,
                "status": "started",
                "message": "Job started"
            }

    def update(self, job_id, current, message=None):
        with self._lock:
            if job_id in self._progress:
                self._progress[job_id]["current"] = current
                if message:
                    self._progress[job_id]["message"] = message  # No emoji, just message

    def complete(self, job_id):
        with self._lock:
            if job_id in self._progress:
                self._progress[job_id]["status"] = "complete"
                self._progress[job_id]["message"] = "Job complete"

    def get(self, job_id):
        with self._lock:
            return self._progress.get(job_id, None)

progress_tracker = ProgressTracker()