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 committed Mar 13, 2024
1 parent cdd847f commit ffc57e7
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 NO_VALUE, 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 @@ -2414,22 +2414,24 @@ def examine_rule(rule_id: str, *, session: "Session") -> dict[str, Any]:


@transactional_session
def get_evaluation_backlog(expiration_time: int = 600, *, session: "Session") -> tuple[int, datetime]:
def get_evaluation_backlog(expiration_time: int = 600, *, session: "Session") -> Union[NoValue, tuple[int, datetime]]:
"""
Counts the number of entries in the rule evaluation backlog.
(Number of files to be evaluated)
:returns: Tuple (Count, Datetime of oldest entry)
"""

cached_backlog = REGION.get('rule_evaluation_backlog', expiration_time=expiration_time)
cached_backlog: Union[NoValue, tuple[int, datetime]] = 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()
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 ffc57e7

Please sign in to comment.