Skip to content

Commit

Permalink
fix circular import issue
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBelthle committed Oct 1, 2024
1 parent d8c3f51 commit 543254e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 128 deletions.
13 changes: 0 additions & 13 deletions antarest/core/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@
from pathlib import Path

import py7zr
import redis
from fastapi import HTTPException
from pydantic import BaseModel, ConfigDict

from antarest.core.config import RedisConfig
from antarest.core.exceptions import ShouldNotHappenException

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -147,17 +145,6 @@ def get_local_path() -> Path:
return filepath


def new_redis_instance(config: RedisConfig) -> redis.Redis: # type: ignore
redis_client = redis.Redis(
host=config.host,
port=config.port,
password=config.password,
db=0,
retry_on_error=[redis.ConnectionError, redis.TimeoutError], # type: ignore
)
return redis_client # type: ignore


class StopWatch:
def __init__(self) -> None:
self.current_time: float = time.time()
Expand Down
14 changes: 12 additions & 2 deletions antarest/service_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

from antarest.core.application import AppBuildContext
from antarest.core.cache.main import build_cache
from antarest.core.config import Config
from antarest.core.config import Config, RedisConfig
from antarest.core.filetransfer.main import build_filetransfer_service
from antarest.core.filetransfer.service import FileTransferManager
from antarest.core.interfaces.cache import ICache
Expand All @@ -34,7 +34,6 @@
from antarest.core.persistence import upgrade_db
from antarest.core.tasks.main import build_taskjob_manager
from antarest.core.tasks.service import ITaskService
from antarest.core.utils.utils import new_redis_instance
from antarest.eventbus.main import build_eventbus
from antarest.launcher.main import build_launcher
from antarest.login.main import build_login
Expand Down Expand Up @@ -109,6 +108,17 @@ def init_db_engine(
return engine


def new_redis_instance(config: RedisConfig) -> redis.Redis: # type: ignore
redis_client = redis.Redis(
host=config.host,
port=config.port,
password=config.password,
db=0,
retry_on_error=[redis.ConnectionError, redis.TimeoutError], # type: ignore
)
return redis_client # type: ignore


def create_event_bus(app_ctxt: t.Optional[AppBuildContext], config: Config) -> t.Tuple[IEventBus, t.Optional[redis.Redis]]: # type: ignore
redis_client = new_redis_instance(config.redis) if config.redis is not None else None
return (
Expand Down
Loading

0 comments on commit 543254e

Please sign in to comment.