first
This commit is contained in:
39
backend/app/scan_state.py
Normal file
39
backend/app/scan_state.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
|
||||
class ScanState:
|
||||
def __init__(self):
|
||||
self.status: str = "idle" # idle, scanning, done, error
|
||||
self.last_scan: Optional[datetime] = None
|
||||
self.progress: int = 0
|
||||
self.total: int = 0
|
||||
self.error: str = ""
|
||||
|
||||
def start(self):
|
||||
self.status = "scanning"
|
||||
self.progress = 0
|
||||
self.total = 0
|
||||
self.error = ""
|
||||
|
||||
def finish(self, count: int):
|
||||
self.status = "done"
|
||||
self.progress = count
|
||||
self.total = count
|
||||
self.last_scan = datetime.utcnow()
|
||||
|
||||
def fail(self, error: str):
|
||||
self.status = "error"
|
||||
self.error = error
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
return {
|
||||
"scan_status": self.status,
|
||||
"last_scan": self.last_scan.isoformat() if self.last_scan else None,
|
||||
"progress": self.progress,
|
||||
"total": self.total,
|
||||
"error": self.error,
|
||||
}
|
||||
|
||||
|
||||
scan_state = ScanState()
|
||||
Reference in New Issue
Block a user