Implement basic error logging
This commit is contained in:
parent
c39f9ed250
commit
1d683b1163
0
src/__init__.py
Normal file
0
src/__init__.py
Normal file
|
@ -1,3 +1,4 @@
|
||||||
from .repo import Repo
|
from .repo import Repo
|
||||||
from .archive import Archive
|
from .archive import Archive
|
||||||
from .stats import Stats
|
from .stats import Stats
|
||||||
|
from .error import Error
|
||||||
|
|
17
src/borg/error.py
Normal file
17
src/borg/error.py
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
|
class Error(object):
|
||||||
|
def __init__(self, error: str, time: datetime):
|
||||||
|
self.error = error
|
||||||
|
self.time = time
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_json(cls, json: dict):
|
||||||
|
error = json['error']
|
||||||
|
time = datetime.fromisoformat(json['time'])
|
||||||
|
return cls(error, time)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_sql(cls, sql: list):
|
||||||
|
pass
|
|
@ -1,4 +1,5 @@
|
||||||
from .connection import RepoConn, ArchiveConn, StatsConn, ErrorConn
|
from .connection import RepoConn, ArchiveConn, StatsConn, ErrorConn
|
||||||
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from src import borg
|
from src import borg
|
||||||
import json
|
import json
|
||||||
|
@ -25,6 +26,7 @@ class BorgDatabase(object):
|
||||||
borg_json = json.loads(borg_output)
|
borg_json = json.loads(borg_output)
|
||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
self.handle_borg_error(borg_output)
|
self.handle_borg_error(borg_output)
|
||||||
|
return
|
||||||
self.process_borg_json(borg_json)
|
self.process_borg_json(borg_json)
|
||||||
|
|
||||||
def process_borg_json(self, borg_json: dict):
|
def process_borg_json(self, borg_json: dict):
|
||||||
|
@ -37,4 +39,5 @@ class BorgDatabase(object):
|
||||||
self.stats_conn.insert(stats, repo_id, archive_id)
|
self.stats_conn.insert(stats, repo_id, archive_id)
|
||||||
|
|
||||||
def handle_borg_error(self, borg_error: str):
|
def handle_borg_error(self, borg_error: str):
|
||||||
pass
|
error = borg.Error(borg_error, datetime.now())
|
||||||
|
self.error_conn.insert(error)
|
||||||
|
|
|
@ -17,8 +17,6 @@ class ErrorConn(DatabaseConnection):
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
def _insert(self, record, repo_id=None, archive_id=None) -> int:
|
def _insert(self, record, repo_id=None, archive_id=None) -> int:
|
||||||
if repo_id is None or archive_id is None:
|
|
||||||
raise Exception("Repo and archive ids not supplied")
|
|
||||||
with self.sql_lock:
|
with self.sql_lock:
|
||||||
cursor = self.sql_cursor
|
cursor = self.sql_cursor
|
||||||
statement = f"INSERT INTO {self._sql_table}"\
|
statement = f"INSERT INTO {self._sql_table}"\
|
||||||
|
|
Loading…
Reference in New Issue
Block a user