Skip to content

Commit

Permalink
Add username to failed syncs
Browse files Browse the repository at this point in the history
  • Loading branch information
luxusko committed Sep 5, 2023
1 parent 7f5201b commit 97b4cda
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
10 changes: 7 additions & 3 deletions server/mergin/sync/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,11 @@ def file_history(self, file, since, to, diffable=False):

return history

def sync_failed(self, client, error_type, error_details):
def sync_failed(self, client, error_type, error_details, username):
"""Commit failed attempt to sync failure history table"""
new_failure = SyncFailuresHistory(self, client, error_type, error_details)
new_failure = SyncFailuresHistory(
self, client, error_type, error_details, username
)
db.session.add(new_failure)
db.session.commit()

Expand Down Expand Up @@ -583,13 +585,15 @@ class SyncFailuresHistory(db.Model):
) # e.g. push_start, push_finish, push_lost
error_details = db.Column(db.String, index=True)
timestamp = db.Column(db.DateTime(), default=datetime.utcnow, index=True)
username = db.Column(db.String, nullable=True)

def __init__(self, project, ua, err_type, err_details):
def __init__(self, project, ua, err_type, err_details, username):
self.user_agent = ua
self.error_type = err_type
self.error_details = err_details
self.project_id = project.id
self.last_version = project.latest_version
self.username = username


class GeodiffActionHistory(db.Model):
Expand Down
9 changes: 7 additions & 2 deletions server/mergin/sync/public_api_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,9 @@ def wrapper(*args, **kwargs):
if not e.description: # custom error cases (e.g. StorageLimitHit)
e.description = e.response.json["detail"]
if project:
project.sync_failed(user_agent, error_type, str(e.description))
project.sync_failed(
user_agent, error_type, str(e.description), current_user.username
)
else:
logging.warning("Missing project info in sync failure")

Expand Down Expand Up @@ -810,7 +812,10 @@ def project_push(namespace, project_name):
db.session.commit()
# previous push attempt is definitely lost
project.sync_failed(
"", "push_lost", "Push artefact removed by subsequent push"
"",
"push_lost",
"Push artefact removed by subsequent push",
current_user.username,
)

# Try again after cleanup
Expand Down

0 comments on commit 97b4cda

Please sign in to comment.