Skip to content

Commit

Permalink
Typing: Fix SQLA query and type hints in get_evaluation_backlog; #6550
Browse files Browse the repository at this point in the history
  • Loading branch information
rdimaio authored and bari12 committed Mar 13, 2024
1 parent cdd847f commit ec84fe0
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/rucio/core/rule.py
Expand Up @@ -22,9 +22,9 @@
from os import path
from re import match
from string import Template
from typing import TYPE_CHECKING, Any, Callable, Literal, Optional, Type, TypeVar
from typing import TYPE_CHECKING, Any, Callable, Literal, Optional, Type, TypeVar, Union

from dogpile.cache.api import NO_VALUE
from dogpile.cache.api import NoValue
from sqlalchemy import select, update
from sqlalchemy.exc import IntegrityError, StatementError
from sqlalchemy.exc import NoResultFound # https://pydoc.dev/sqlalchemy/latest/sqlalchemy.exc.NoResultFound.html
Expand Down Expand Up @@ -2422,14 +2422,16 @@ def get_evaluation_backlog(expiration_time: int = 600, *, session: "Session") ->
:returns: Tuple (Count, Datetime of oldest entry)
"""

cached_backlog = REGION.get('rule_evaluation_backlog', expiration_time=expiration_time)
if cached_backlog is NO_VALUE:
stmt = select(func.count(models.UpdatedDID.created_at), func.min(models.UpdatedDID.created_at))
result = session.execute(stmt).scalars().one()
cached_backlog: Union[NoValue, tuple[int, datetime]] = REGION.get('rule_evaluation_backlog', expiration_time=expiration_time)
if isinstance(cached_backlog, NoValue):
stmt = select(
func.count(models.UpdatedDID.created_at),
func.min(models.UpdatedDID.created_at)
)
result = session.execute(stmt).one()._tuple()
REGION.set('rule_evaluation_backlog', result)
return result
else:
return cached_backlog # type: ignore
return cached_backlog


@transactional_session
Expand Down

0 comments on commit ec84fe0

Please sign in to comment.