Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Oct 29, 2024
1 parent e818824 commit fa679b1
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/aiida/engine/transports.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import contextvars
import logging
import traceback
from datetime import datetime
from typing import TYPE_CHECKING, Awaitable, Dict, Hashable, Iterator, Optional

from aiida.common import timezone
Expand Down Expand Up @@ -130,13 +129,15 @@ def do_open():
if timedelta_seconds > safe_open_interval:
# ! This could also be `_loop.call_soon` which has an implicit delay of 0s

open_timedelta = timedelta_seconds-safe_open_interval
open_timedelta = timedelta_seconds - safe_open_interval
open_callback_handle = self._loop.call_later(open_timedelta, do_open, context=contextvars.Context())
self._last_request_special = True

else:
# If the last one was a special request, wait the safe_open_interval
open_callback_handle = self._loop.call_later(safe_open_interval, do_open, context=contextvars.Context())
open_callback_handle = self._loop.call_later(
safe_open_interval, do_open, context=contextvars.Context()
)

# open_callback_handle = self._loop.call_later(safe_open_interval, do_open, context=contextvars.Context())

Expand All @@ -163,22 +164,22 @@ def do_close():
transport_request.future.result().close()
# self._last_close_time = timezone.localtime(timezone.now())

close_timedelta = (timezone.localtime(timezone.now()) - self._last_open_time).total_seconds()
close_timedelta = (timezone.localtime(timezone.now()) - self._last_open_time).total_seconds()

if close_timedelta > safe_open_interval:

# Also here logic when transport should be closed immediately, or when via call_later?
close_callback_handle = self._loop.call_soon(do_close, context=contextvars.Context())
self._last_close_time = timezone.localtime(timezone.now())
else:
close_callback_handle = self._loop.call_later(safe_open_interval, do_close, context=contextvars.Context())

close_callback_handle = self._loop.call_later(
safe_open_interval, do_close, context=contextvars.Context()
)

# transport_request.transport_closer = close_callback_handle

# This should be replaced with the call_later close_callback_handle invocation
# transport_request.future.result().close()


elif open_callback_handle is not None:
open_callback_handle.cancel()

Expand Down

0 comments on commit fa679b1

Please sign in to comment.