remove old import
This commit is contained in:
@@ -27,6 +27,8 @@ from app.auth.security import get_admin_user, get_password_hash, create_access_t
|
||||
from app.services.audit import audit_service
|
||||
from app.config import settings
|
||||
from app.services.query_utils import apply_sorting, tokenized_ilike_filter, paginate_with_total
|
||||
from app.utils.exceptions import handle_database_errors, safe_execute
|
||||
from app.utils.logging import app_logger
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -304,7 +306,8 @@ async def system_health(
|
||||
disk_available = free_gb > 1.0 # 1GB minimum
|
||||
if not disk_available:
|
||||
alerts.append(f"Low disk space: {free_gb:.1f}GB remaining")
|
||||
except:
|
||||
except (OSError, ImportError) as e:
|
||||
app_logger.warning(f"Could not check disk space: {str(e)}")
|
||||
disk_available = True
|
||||
|
||||
# Check memory (simplified)
|
||||
@@ -331,7 +334,8 @@ async def system_health(
|
||||
active_sessions = db.query(User).filter(
|
||||
User.last_login > datetime.now(timezone.utc) - timedelta(hours=24)
|
||||
).count()
|
||||
except:
|
||||
except Exception as e:
|
||||
app_logger.warning(f"Could not query active sessions: {str(e)}")
|
||||
active_sessions = 0
|
||||
|
||||
# Check last backup
|
||||
@@ -346,7 +350,8 @@ async def system_health(
|
||||
last_backup = latest_backup.name
|
||||
if backup_age.days > 7:
|
||||
alerts.append(f"Last backup is {backup_age.days} days old")
|
||||
except:
|
||||
except (OSError, FileNotFoundError) as e:
|
||||
app_logger.warning(f"Could not check backup status: {str(e)}")
|
||||
alerts.append("Unable to check backup status")
|
||||
|
||||
# Application uptime
|
||||
@@ -398,8 +403,8 @@ async def system_statistics(
|
||||
if os.path.exists(db_path):
|
||||
size_bytes = os.path.getsize(db_path)
|
||||
db_size = f"{size_bytes / (1024*1024):.1f} MB"
|
||||
except:
|
||||
pass
|
||||
except (OSError, ValueError) as e:
|
||||
app_logger.warning(f"Could not get database size: {str(e)}")
|
||||
|
||||
# Check for recent backups
|
||||
last_backup = "Not found"
|
||||
@@ -410,8 +415,8 @@ async def system_statistics(
|
||||
if backup_files:
|
||||
latest_backup = max(backup_files, key=lambda p: p.stat().st_mtime)
|
||||
last_backup = latest_backup.name
|
||||
except:
|
||||
pass
|
||||
except (OSError, FileNotFoundError) as e:
|
||||
app_logger.warning(f"Could not check for recent backups: {str(e)}")
|
||||
|
||||
# Application uptime
|
||||
uptime_seconds = int(time.time() - APPLICATION_START_TIME)
|
||||
@@ -437,8 +442,8 @@ async def system_statistics(
|
||||
"description": f"Customer {customer.first} {customer.last} added",
|
||||
"timestamp": datetime.now(timezone.utc).isoformat()
|
||||
})
|
||||
except:
|
||||
pass
|
||||
except Exception as e:
|
||||
app_logger.warning(f"Could not get recent activity: {str(e)}")
|
||||
|
||||
return SystemStats(
|
||||
total_customers=total_customers,
|
||||
|
||||
@@ -16,6 +16,8 @@ from app.auth.security import get_current_user
|
||||
from app.services.cache import invalidate_search_cache
|
||||
from app.services.customers_search import apply_customer_filters, apply_customer_sorting, prepare_customer_csv_rows
|
||||
from app.services.query_utils import apply_sorting, paginate_with_total
|
||||
from app.utils.logging import app_logger
|
||||
from app.utils.database import db_transaction
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -321,14 +323,15 @@ async def create_customer(
|
||||
)
|
||||
|
||||
customer = Rolodex(**customer_data.model_dump())
|
||||
db.add(customer)
|
||||
db.commit()
|
||||
db.refresh(customer)
|
||||
with db_transaction(db) as session:
|
||||
session.add(customer)
|
||||
session.flush()
|
||||
session.refresh(customer)
|
||||
|
||||
try:
|
||||
await invalidate_search_cache()
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
app_logger.warning(f"Failed to invalidate search cache: {str(e)}")
|
||||
return customer
|
||||
|
||||
|
||||
@@ -352,12 +355,13 @@ async def update_customer(
|
||||
for field, value in customer_data.model_dump(exclude_unset=True).items():
|
||||
setattr(customer, field, value)
|
||||
|
||||
db.commit()
|
||||
db.refresh(customer)
|
||||
with db_transaction(db) as session:
|
||||
session.flush()
|
||||
session.refresh(customer)
|
||||
try:
|
||||
await invalidate_search_cache()
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
app_logger.warning(f"Failed to invalidate search cache: {str(e)}")
|
||||
return customer
|
||||
|
||||
|
||||
@@ -376,12 +380,12 @@ async def delete_customer(
|
||||
detail="Customer not found"
|
||||
)
|
||||
|
||||
db.delete(customer)
|
||||
db.commit()
|
||||
with db_transaction(db) as session:
|
||||
session.delete(customer)
|
||||
try:
|
||||
await invalidate_search_cache()
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
app_logger.warning(f"Failed to invalidate search cache: {str(e)}")
|
||||
return {"message": "Customer deleted successfully"}
|
||||
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ from app.models.additional import Payment, Deposit, FileNote, FormVariable, Repo
|
||||
from app.models.flexible import FlexibleImport
|
||||
from app.models.audit import ImportAudit, ImportAuditFile
|
||||
from app.config import settings
|
||||
from app.utils.logging import import_logger
|
||||
|
||||
router = APIRouter(tags=["import"])
|
||||
|
||||
@@ -931,7 +932,7 @@ async def import_csv_data(
|
||||
rows_data.append(row_dict)
|
||||
|
||||
except Exception as row_error:
|
||||
print(f"Skipping malformed row {line_num}: {row_error}")
|
||||
import_logger.log_import_error(line_num, str(row_error), dict(zip(headers, fields)) if len(fields) <= len(headers) else None)
|
||||
skipped_rows += 1
|
||||
continue
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ from app.models.lookups import FormIndex, Employee, FileType, FileStatus, Transa
|
||||
from app.models.user import User
|
||||
from app.auth.security import get_current_user
|
||||
from app.services.cache import cache_get_json, cache_set_json
|
||||
from app.utils.logging import app_logger
|
||||
|
||||
router = APIRouter()
|
||||
@router.get("/_debug")
|
||||
@@ -48,15 +49,16 @@ async def search_debug(
|
||||
fts_status["files"] = "files_fts" in names
|
||||
fts_status["ledger"] = "ledger_fts" in names
|
||||
fts_status["qdros"] = "qdros_fts" in names
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
app_logger.warning(f"Failed to check FTS status: {str(e)}")
|
||||
|
||||
# Detect Redis by trying to obtain a client
|
||||
try:
|
||||
from app.services.cache import _get_client # type: ignore
|
||||
client = await _get_client()
|
||||
redis_ok = client is not None
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
app_logger.debug(f"Redis not available: {str(e)}")
|
||||
redis_ok = False
|
||||
return {
|
||||
"fts": fts_status,
|
||||
|
||||
Reference in New Issue
Block a user