- Added EveAI Client to project
- Improvements to EntitlementsDomain & Services - Prechecks in Document domain - Add audit information to LicenseUsage
This commit is contained in:
@@ -8,7 +8,7 @@ from sqlalchemy.exc import SQLAlchemyError
|
||||
from common.extensions import db
|
||||
from common.models.user import Tenant
|
||||
from common.models.entitlements import BusinessEventLog, LicenseUsage, License
|
||||
from common.services.entitlements.license_period_services import LicensePeriodServices
|
||||
from common.services.entitlements import LicensePeriodServices
|
||||
from common.utils.celery_utils import current_celery
|
||||
from common.utils.eveai_exceptions import EveAINoLicenseForTenant, EveAIException, EveAINoActiveLicense
|
||||
from common.utils.database import Database
|
||||
@@ -149,7 +149,7 @@ def process_logs_for_license_usage(tenant_id, license_usage, logs):
|
||||
license_usage.interaction_total_tokens_used += interaction_total_tokens_used
|
||||
|
||||
if recalculate_storage:
|
||||
recalculate_storage_for_tenant(tenant_id)
|
||||
license_usage.recalculate_storage()
|
||||
|
||||
# Commit the updates to the LicenseUsage and log records
|
||||
try:
|
||||
@@ -163,24 +163,4 @@ def process_logs_for_license_usage(tenant_id, license_usage, logs):
|
||||
raise e
|
||||
|
||||
|
||||
def recalculate_storage_for_tenant(tenant_id):
|
||||
Database(tenant_id).switch_schema()
|
||||
# Perform a SUM operation to get the total file size from document_versions
|
||||
total_storage = db.session.execute(text(f"""
|
||||
SELECT SUM(file_size)
|
||||
FROM document_version
|
||||
""")).scalar()
|
||||
|
||||
# Update the LicenseUsage with the recalculated storage
|
||||
license_usage = db.session.query(LicenseUsage).filter_by(tenant_id=tenant_id).first()
|
||||
license_usage.storage_mb_used = total_storage
|
||||
|
||||
# Commit the changes
|
||||
try:
|
||||
db.session.add(license_usage)
|
||||
db.session.commit()
|
||||
except SQLAlchemyError as e:
|
||||
db.session.rollback()
|
||||
current_app.logger.error(f"Error trying to update tenant {tenant_id} for Dirty Storage. ")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user