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

Resolving concurrency conflcts during fetching operation #1243

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion ersilia/serve/autoservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from ..db.environments.managers import DockerManager
from .. import ErsiliaBase
from ..utils import tmp_pid_file
from ..utils.session import get_session_id

from ..default import (
DEFAULT_BATCH_SIZE,
Expand Down Expand Up @@ -315,10 +316,11 @@ def clean_before_serving(self):
self._kill_pids(pids)

def clean_temp_dir(self):
session_id = get_session_id()
self.logger.debug("Cleaning temp dir")
tmp_folder = tempfile.gettempdir()
for d in os.listdir(tmp_folder):
if "ersilia-" in d:
if f"ersilia-{session_id}-" in d:
d = os.path.join(tmp_folder, d)
self.logger.debug("Flushing temporary directory {0}".format(d))
try:
Expand Down Expand Up @@ -395,3 +397,4 @@ def api(
if api_name not in self._meta:
self._meta = {api_name: _api.meta()}
yield result

7 changes: 5 additions & 2 deletions ersilia/utils/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
import tempfile
from loguru import logger
from ..default import LOGGING_FILE, CURRENT_LOGGING_FILE, VERBOSE_FILE
from ..utils.session import get_session_dir
from ..utils.session import get_session_dir, get_session_id


ROTATION = "10 MB"


def make_temp_dir(prefix):
tmp_dir = tempfile.mkdtemp(prefix=prefix)
session_id = get_session_id()
prefix_with_session = f"{prefix}{session_id}-"
tmp_dir = tempfile.mkdtemp(prefix=prefix_with_session)
tmp_dirname = os.path.basename(tmp_dir)
logs_tmp_dir = os.path.join(get_session_dir(), "logs", "tmp")
if not os.path.exists(logs_tmp_dir):
Expand Down Expand Up @@ -98,3 +100,4 @@ def success(self, text):


logger = Logger()