forked from retoor/devplacepy
update
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
import threading
|
||||
|
||||
|
||||
@dataclass
|
||||
class RequestCounters:
|
||||
requests: int = 0
|
||||
errors: int = 0
|
||||
_lock: threading.Lock = field(default_factory=threading.Lock, repr=False)
|
||||
|
||||
def record_request(self) -> None:
|
||||
with self._lock:
|
||||
self.requests += 1
|
||||
|
||||
def record_error(self) -> None:
|
||||
with self._lock:
|
||||
self.errors += 1
|
||||
|
||||
def snapshot(self) -> dict[str, int]:
|
||||
with self._lock:
|
||||
return {"requests": self.requests, "errors": self.errors}
|
||||
|
||||
|
||||
COUNTERS = RequestCounters()
|
||||
Reference in New Issue
Block a user