Spaces:
Running
Running
add retry_db to all pg_crud functions
Browse files
externals/databases/pg_crud.py
CHANGED
|
@@ -149,6 +149,7 @@ async def mark_file_extracted(
|
|
| 149 |
await db.commit()
|
| 150 |
|
| 151 |
|
|
|
|
| 152 |
async def create_cv_file(
|
| 153 |
db: AsyncSession,
|
| 154 |
*,
|
|
@@ -182,6 +183,8 @@ async def delete_file_by_filename(
|
|
| 182 |
await db.commit()
|
| 183 |
return result.rowcount > 0
|
| 184 |
|
|
|
|
|
|
|
| 185 |
async def get_file_by_user_id(
|
| 186 |
db: AsyncSession,
|
| 187 |
user_id: str,
|
|
@@ -191,6 +194,8 @@ async def get_file_by_user_id(
|
|
| 191 |
)
|
| 192 |
return result.scalars().all()
|
| 193 |
|
|
|
|
|
|
|
| 194 |
async def get_file_by_filename(
|
| 195 |
db: AsyncSession,
|
| 196 |
filename: str,
|
|
@@ -207,6 +212,7 @@ async def get_file_by_filename(
|
|
| 207 |
return result.scalar_one_or_none()
|
| 208 |
|
| 209 |
|
|
|
|
| 210 |
async def count_files_by_user(
|
| 211 |
db: AsyncSession,
|
| 212 |
user_id: str,
|
|
@@ -218,6 +224,7 @@ async def count_files_by_user(
|
|
| 218 |
return int(result.scalar_one())
|
| 219 |
|
| 220 |
|
|
|
|
| 221 |
async def count_profiles_by_user(
|
| 222 |
db: AsyncSession,
|
| 223 |
user_id: str,
|
|
@@ -231,6 +238,7 @@ async def count_profiles_by_user(
|
|
| 231 |
return int(result.scalar_one())
|
| 232 |
|
| 233 |
|
|
|
|
| 234 |
async def mark_file_extracted(db: AsyncSession, file_id: UUID):
|
| 235 |
await db.execute(
|
| 236 |
update(CVFile)
|
|
@@ -253,6 +261,7 @@ async def mark_file_extracted(db: AsyncSession, file_id: UUID):
|
|
| 253 |
|
| 254 |
from services.models.data_model import AIProfile
|
| 255 |
|
|
|
|
| 256 |
async def create_profile(
|
| 257 |
db: AsyncSession,
|
| 258 |
filename: str,
|
|
@@ -290,6 +299,7 @@ async def create_profile(
|
|
| 290 |
return profile
|
| 291 |
|
| 292 |
|
|
|
|
| 293 |
async def get_profile_by_filename(
|
| 294 |
db: AsyncSession,
|
| 295 |
filename: str,
|
|
@@ -303,6 +313,8 @@ async def get_profile_by_filename(
|
|
| 303 |
result = await db.execute(stmt)
|
| 304 |
return result.scalar_one_or_none()
|
| 305 |
|
|
|
|
|
|
|
| 306 |
async def get_profiles(
|
| 307 |
db: AsyncSession,
|
| 308 |
) -> List[CVProfile]:
|
|
@@ -310,13 +322,14 @@ async def get_profiles(
|
|
| 310 |
result = await db.execute(stmt)
|
| 311 |
return result.scalars().all()
|
| 312 |
|
| 313 |
-
from sqlalchemy import func
|
| 314 |
|
| 315 |
from sqlalchemy import select, and_, func, cast, String
|
| 316 |
from sqlalchemy.ext.asyncio import AsyncSession
|
| 317 |
from sqlalchemy.dialects.postgresql import ARRAY
|
| 318 |
from typing import List
|
| 319 |
|
|
|
|
|
|
|
| 320 |
async def get_profiles_by_criteria_id(
|
| 321 |
db: AsyncSession,
|
| 322 |
criteria_id: str,
|
|
@@ -448,7 +461,7 @@ async def get_profiles_by_criteria_id(
|
|
| 448 |
# result = await db.execute(stmt)
|
| 449 |
# return result.scalar_one_or_none()
|
| 450 |
|
| 451 |
-
from typing import Tuple
|
| 452 |
|
| 453 |
# async def get_profile_by_id(
|
| 454 |
# db: AsyncSession,
|
|
@@ -469,7 +482,7 @@ from typing import Tuple
|
|
| 469 |
|
| 470 |
# return result
|
| 471 |
|
| 472 |
-
|
| 473 |
async def get_profile_by_id(
|
| 474 |
db: AsyncSession,
|
| 475 |
profile_id: str,
|
|
@@ -501,6 +514,7 @@ async def get_profile_by_id(
|
|
| 501 |
return profile_dict
|
| 502 |
|
| 503 |
|
|
|
|
| 504 |
async def list_profiles(
|
| 505 |
db: AsyncSession,
|
| 506 |
limit: int = 50,
|
|
@@ -517,6 +531,7 @@ async def list_profiles(
|
|
| 517 |
from sqlalchemy import select, and_
|
| 518 |
from sqlalchemy.ext.asyncio import AsyncSession
|
| 519 |
|
|
|
|
| 520 |
async def get_filter(
|
| 521 |
db: AsyncSession,
|
| 522 |
filter: CVFilter,
|
|
@@ -577,6 +592,7 @@ async def get_filter(
|
|
| 577 |
return result.scalar_one_or_none()
|
| 578 |
|
| 579 |
|
|
|
|
| 580 |
async def get_filter_by_id(
|
| 581 |
db: AsyncSession,
|
| 582 |
criteria_id: str,
|
|
@@ -586,7 +602,7 @@ async def get_filter_by_id(
|
|
| 586 |
return result.scalar_one_or_none()
|
| 587 |
|
| 588 |
|
| 589 |
-
|
| 590 |
async def create_filter(
|
| 591 |
db: AsyncSession,
|
| 592 |
filter: CVFilter,
|
|
@@ -596,6 +612,7 @@ async def create_filter(
|
|
| 596 |
return filter
|
| 597 |
|
| 598 |
|
|
|
|
| 599 |
async def get_filter_and_weight(
|
| 600 |
db: AsyncSession,
|
| 601 |
criteria_id: str,
|
|
@@ -609,6 +626,7 @@ async def get_filter_and_weight(
|
|
| 609 |
return result.scalar_one_or_none()
|
| 610 |
|
| 611 |
|
|
|
|
| 612 |
async def get_weight_by_id(
|
| 613 |
db: AsyncSession,
|
| 614 |
weight_id: str,
|
|
@@ -620,6 +638,8 @@ async def get_weight_by_id(
|
|
| 620 |
result = await db.execute(stmt)
|
| 621 |
return result.scalar_one_or_none()
|
| 622 |
|
|
|
|
|
|
|
| 623 |
async def create_filter_and_weight(
|
| 624 |
db: AsyncSession,
|
| 625 |
cv_filter: CVFilter,
|
|
@@ -628,6 +648,8 @@ async def create_filter_and_weight(
|
|
| 628 |
db.add_all([cv_filter, cv_weight])
|
| 629 |
await db.commit()
|
| 630 |
|
|
|
|
|
|
|
| 631 |
async def create_weight(
|
| 632 |
db: AsyncSession,
|
| 633 |
cv_weight: CVWeight,
|
|
@@ -640,6 +662,7 @@ async def create_weight(
|
|
| 640 |
# MATCHING
|
| 641 |
# =========================
|
| 642 |
|
|
|
|
| 643 |
async def create_matching(
|
| 644 |
db: AsyncSession,
|
| 645 |
matching: CVMatching,
|
|
@@ -650,8 +673,7 @@ async def create_matching(
|
|
| 650 |
return matching
|
| 651 |
|
| 652 |
|
| 653 |
-
|
| 654 |
-
|
| 655 |
async def create_matchings(
|
| 656 |
db: AsyncSession,
|
| 657 |
matchings: list,
|
|
@@ -671,6 +693,7 @@ async def create_matchings(
|
|
| 671 |
raise
|
| 672 |
|
| 673 |
|
|
|
|
| 674 |
async def get_matching_by_profile_and_criteria(
|
| 675 |
db: AsyncSession,
|
| 676 |
profile_id: str,
|
|
@@ -692,7 +715,7 @@ async def get_matching_by_profile_and_criteria(
|
|
| 692 |
# =========================
|
| 693 |
# SCORE
|
| 694 |
# =========================
|
| 695 |
-
|
| 696 |
async def create_score(
|
| 697 |
db: AsyncSession,
|
| 698 |
score: CVScore,
|
|
@@ -703,6 +726,7 @@ async def create_score(
|
|
| 703 |
return score
|
| 704 |
|
| 705 |
|
|
|
|
| 706 |
async def create_scores(
|
| 707 |
db: AsyncSession,
|
| 708 |
scores: list[CVScore],
|
|
@@ -718,6 +742,7 @@ async def create_scores(
|
|
| 718 |
raise
|
| 719 |
|
| 720 |
|
|
|
|
| 721 |
async def get_scores_by_criteria(
|
| 722 |
db: AsyncSession,
|
| 723 |
criteria_id: str,
|
|
|
|
| 149 |
await db.commit()
|
| 150 |
|
| 151 |
|
| 152 |
+
@retry_db(retries=2, delay=2)
|
| 153 |
async def create_cv_file(
|
| 154 |
db: AsyncSession,
|
| 155 |
*,
|
|
|
|
| 183 |
await db.commit()
|
| 184 |
return result.rowcount > 0
|
| 185 |
|
| 186 |
+
|
| 187 |
+
@retry_db(retries=2, delay=2)
|
| 188 |
async def get_file_by_user_id(
|
| 189 |
db: AsyncSession,
|
| 190 |
user_id: str,
|
|
|
|
| 194 |
)
|
| 195 |
return result.scalars().all()
|
| 196 |
|
| 197 |
+
|
| 198 |
+
@retry_db(retries=2, delay=2)
|
| 199 |
async def get_file_by_filename(
|
| 200 |
db: AsyncSession,
|
| 201 |
filename: str,
|
|
|
|
| 212 |
return result.scalar_one_or_none()
|
| 213 |
|
| 214 |
|
| 215 |
+
@retry_db(retries=2, delay=2)
|
| 216 |
async def count_files_by_user(
|
| 217 |
db: AsyncSession,
|
| 218 |
user_id: str,
|
|
|
|
| 224 |
return int(result.scalar_one())
|
| 225 |
|
| 226 |
|
| 227 |
+
@retry_db(retries=2, delay=2)
|
| 228 |
async def count_profiles_by_user(
|
| 229 |
db: AsyncSession,
|
| 230 |
user_id: str,
|
|
|
|
| 238 |
return int(result.scalar_one())
|
| 239 |
|
| 240 |
|
| 241 |
+
@retry_db(retries=2, delay=2)
|
| 242 |
async def mark_file_extracted(db: AsyncSession, file_id: UUID):
|
| 243 |
await db.execute(
|
| 244 |
update(CVFile)
|
|
|
|
| 261 |
|
| 262 |
from services.models.data_model import AIProfile
|
| 263 |
|
| 264 |
+
@retry_db(retries=2, delay=2)
|
| 265 |
async def create_profile(
|
| 266 |
db: AsyncSession,
|
| 267 |
filename: str,
|
|
|
|
| 299 |
return profile
|
| 300 |
|
| 301 |
|
| 302 |
+
@retry_db(retries=2, delay=2)
|
| 303 |
async def get_profile_by_filename(
|
| 304 |
db: AsyncSession,
|
| 305 |
filename: str,
|
|
|
|
| 313 |
result = await db.execute(stmt)
|
| 314 |
return result.scalar_one_or_none()
|
| 315 |
|
| 316 |
+
|
| 317 |
+
@retry_db(retries=2, delay=2)
|
| 318 |
async def get_profiles(
|
| 319 |
db: AsyncSession,
|
| 320 |
) -> List[CVProfile]:
|
|
|
|
| 322 |
result = await db.execute(stmt)
|
| 323 |
return result.scalars().all()
|
| 324 |
|
|
|
|
| 325 |
|
| 326 |
from sqlalchemy import select, and_, func, cast, String
|
| 327 |
from sqlalchemy.ext.asyncio import AsyncSession
|
| 328 |
from sqlalchemy.dialects.postgresql import ARRAY
|
| 329 |
from typing import List
|
| 330 |
|
| 331 |
+
|
| 332 |
+
@retry_db(retries=2, delay=2)
|
| 333 |
async def get_profiles_by_criteria_id(
|
| 334 |
db: AsyncSession,
|
| 335 |
criteria_id: str,
|
|
|
|
| 461 |
# result = await db.execute(stmt)
|
| 462 |
# return result.scalar_one_or_none()
|
| 463 |
|
| 464 |
+
# from typing import Tuple
|
| 465 |
|
| 466 |
# async def get_profile_by_id(
|
| 467 |
# db: AsyncSession,
|
|
|
|
| 482 |
|
| 483 |
# return result
|
| 484 |
|
| 485 |
+
@retry_db(retries=2, delay=2)
|
| 486 |
async def get_profile_by_id(
|
| 487 |
db: AsyncSession,
|
| 488 |
profile_id: str,
|
|
|
|
| 514 |
return profile_dict
|
| 515 |
|
| 516 |
|
| 517 |
+
@retry_db(retries=2, delay=2)
|
| 518 |
async def list_profiles(
|
| 519 |
db: AsyncSession,
|
| 520 |
limit: int = 50,
|
|
|
|
| 531 |
from sqlalchemy import select, and_
|
| 532 |
from sqlalchemy.ext.asyncio import AsyncSession
|
| 533 |
|
| 534 |
+
@retry_db(retries=2, delay=2)
|
| 535 |
async def get_filter(
|
| 536 |
db: AsyncSession,
|
| 537 |
filter: CVFilter,
|
|
|
|
| 592 |
return result.scalar_one_or_none()
|
| 593 |
|
| 594 |
|
| 595 |
+
@retry_db(retries=2, delay=2)
|
| 596 |
async def get_filter_by_id(
|
| 597 |
db: AsyncSession,
|
| 598 |
criteria_id: str,
|
|
|
|
| 602 |
return result.scalar_one_or_none()
|
| 603 |
|
| 604 |
|
| 605 |
+
@retry_db(retries=2, delay=2)
|
| 606 |
async def create_filter(
|
| 607 |
db: AsyncSession,
|
| 608 |
filter: CVFilter,
|
|
|
|
| 612 |
return filter
|
| 613 |
|
| 614 |
|
| 615 |
+
@retry_db(retries=2, delay=2)
|
| 616 |
async def get_filter_and_weight(
|
| 617 |
db: AsyncSession,
|
| 618 |
criteria_id: str,
|
|
|
|
| 626 |
return result.scalar_one_or_none()
|
| 627 |
|
| 628 |
|
| 629 |
+
@retry_db(retries=2, delay=2)
|
| 630 |
async def get_weight_by_id(
|
| 631 |
db: AsyncSession,
|
| 632 |
weight_id: str,
|
|
|
|
| 638 |
result = await db.execute(stmt)
|
| 639 |
return result.scalar_one_or_none()
|
| 640 |
|
| 641 |
+
|
| 642 |
+
@retry_db(retries=2, delay=2)
|
| 643 |
async def create_filter_and_weight(
|
| 644 |
db: AsyncSession,
|
| 645 |
cv_filter: CVFilter,
|
|
|
|
| 648 |
db.add_all([cv_filter, cv_weight])
|
| 649 |
await db.commit()
|
| 650 |
|
| 651 |
+
|
| 652 |
+
@retry_db(retries=2, delay=2)
|
| 653 |
async def create_weight(
|
| 654 |
db: AsyncSession,
|
| 655 |
cv_weight: CVWeight,
|
|
|
|
| 662 |
# MATCHING
|
| 663 |
# =========================
|
| 664 |
|
| 665 |
+
@retry_db(retries=2, delay=2)
|
| 666 |
async def create_matching(
|
| 667 |
db: AsyncSession,
|
| 668 |
matching: CVMatching,
|
|
|
|
| 673 |
return matching
|
| 674 |
|
| 675 |
|
| 676 |
+
@retry_db(retries=2, delay=2)
|
|
|
|
| 677 |
async def create_matchings(
|
| 678 |
db: AsyncSession,
|
| 679 |
matchings: list,
|
|
|
|
| 693 |
raise
|
| 694 |
|
| 695 |
|
| 696 |
+
@retry_db(retries=2, delay=2)
|
| 697 |
async def get_matching_by_profile_and_criteria(
|
| 698 |
db: AsyncSession,
|
| 699 |
profile_id: str,
|
|
|
|
| 715 |
# =========================
|
| 716 |
# SCORE
|
| 717 |
# =========================
|
| 718 |
+
@retry_db(retries=2, delay=2)
|
| 719 |
async def create_score(
|
| 720 |
db: AsyncSession,
|
| 721 |
score: CVScore,
|
|
|
|
| 726 |
return score
|
| 727 |
|
| 728 |
|
| 729 |
+
@retry_db(retries=2, delay=2)
|
| 730 |
async def create_scores(
|
| 731 |
db: AsyncSession,
|
| 732 |
scores: list[CVScore],
|
|
|
|
| 742 |
raise
|
| 743 |
|
| 744 |
|
| 745 |
+
@retry_db(retries=2, delay=2)
|
| 746 |
async def get_scores_by_criteria(
|
| 747 |
db: AsyncSession,
|
| 748 |
criteria_id: str,
|