Skip to content

Commit

Permalink
fix(docworker): Fix storage limit in document worker
Browse files Browse the repository at this point in the history
  • Loading branch information
MarekSuchanek committed Dec 19, 2024
1 parent 35f2d37 commit 1f63e27
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/dsw-database/dsw/database/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ class Database:
'FROM document WHERE tenant_uuid = %(tenant_uuid)s) ' \
'+ (SELECT COALESCE(SUM(file_size)::bigint, 0) ' \
'FROM document_template_asset WHERE tenant_uuid = %(tenant_uuid)s) ' \
'as result;'
'+ (SELECT COALESCE(SUM(file_size)::bigint, 0) ' \
'FROM questionnaire_file WHERE tenant_uuid = %(tenant_uuid)s) ' \
'AS result;'

def __init__(self, cfg: DatabaseConfig, connect: bool = True,
with_queue: bool = True):
Expand Down
2 changes: 2 additions & 0 deletions packages/dsw-document-worker/dsw/document_worker/limits.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def check_doc_size(job_id: str, doc_size: int):
@staticmethod
def check_size_usage(job_id: str, doc_size: int,
used_size: int, limit_size: Optional[int]):
limit_size = abs(limit_size) if limit_size is not None else None

if limit_size is None or doc_size + used_size < limit_size:
return
remains = limit_size - used_size
Expand Down
4 changes: 2 additions & 2 deletions packages/dsw-document-worker/dsw/document_worker/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def __init__(self, command: PersistentCommand, document_uuid: str):
self.doc_context = command.body # type: dict
self.doc = None # type: Optional[DBDocument]
self.final_file = None # type: Optional[DocumentFile]
self.tenant_config = None # type: Optional[DBTenantConfig]
self.tenant_limits = None # type: Optional[DBTenantLimits]
self.tenant_config = self.ctx.app.db.get_tenant_config(self.tenant_uuid) # type: Optional[DBTenantConfig]
self.tenant_limits = self.ctx.app.db.fetch_tenant_limits(self.tenant_uuid) # type: Optional[DBTenantLimits]

@property
def safe_doc(self) -> DBDocument:
Expand Down

0 comments on commit 1f63e27

Please sign in to comment.