Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typing: Fix SQLA query and type hints in get_evaluation_backlog #6552

Merged
merged 1 commit into from Mar 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
dchristidis marked this conversation as resolved.
Show resolved Hide resolved
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
bari12 marked this conversation as resolved.
Show resolved Hide resolved


@transactional_session
Expand Down