db_task.py 609 B

123456789101112131415161718192021
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. from sqlalchemy.orm import Session
  4. from sqlalchemy import text, exists, and_, or_, not_
  5. from sqlalchemy.sql import func
  6. from database import get_db
  7. from extensions import logger
  8. import random
  9. from models import *
  10. def get_next_event_id(db: Session):
  11. while True:
  12. random_10_digit_number = random.randint(1000000000, 9999999999)
  13. taskId = 'task' + str(random_10_digit_number)
  14. it_exists = db.query(
  15. exists().where(TaskRegistration.task_id == taskId)
  16. ).scalar()
  17. if it_exists == False:
  18. return taskId