Skip to content

Commit

Permalink
Improved looping job info
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Nilsson committed Jan 31, 2024
1 parent 647970b commit fb50597
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
2 changes: 1 addition & 1 deletion PILOTVERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.7.1.41
3.7.1.42
2 changes: 1 addition & 1 deletion pilot/util/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
RELEASE = '3' # released number should be fixed at 3 for Pilot 3
VERSION = '7' # version number is '1' for first release, '0' until then, increased for bigger updates
REVISION = '1' # revision number should be reset to '0' for every new version release, increased for small updates
BUILD = '41' # build number should be reset to '1' for every new development cycle
BUILD = '42' # build number should be reset to '1' for every new development cycle

SUCCESS = 0
FAILURE = 1
Expand Down
7 changes: 3 additions & 4 deletions pilot/util/loopingjob.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
list_mod_files
)
from pilot.util.heartbeat import time_since_suspension
from pilot.util.math import convert_seconds_to_hours_minutes_seconds
from pilot.util.parameters import convert_to_int
from pilot.util.processes import (
kill_process,
Expand Down Expand Up @@ -98,10 +99,8 @@ def looping_job(job: Any, montime: Any) -> (int, str):
# the payload process is considered to be looping if it's files have not been touched within looping_limit time
if time_last_touched:
currenttime = int(time.time())
logger.info(f'current time: {currenttime}')
logger.info(f'last time files were touched: {time_last_touched}')
logger.info(f'looping limit: {looping_limit} s')

hours, minutes, seconds = convert_seconds_to_hours_minutes_seconds(currenttime - time_last_touched)
logger.info(f'files were last touched {hours}h {minutes}m {seconds}s ago (current time: {currenttime})')
if currenttime - time_last_touched > looping_limit:
try:
# which were the considered files?
Expand Down
38 changes: 28 additions & 10 deletions pilot/util/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ def float_to_rounded_string(num: float, precision: int = 3) -> str:
try:
_precision = Decimal(10) ** -precision
except Exception as exc:
raise NotDefined(f'failed to define precision={precision}: {exc}')
raise NotDefined(f'failed to define precision={precision}: {exc}') from exc

try:
s = Decimal(str(num)).quantize(_precision)
except Exception as exc:
raise NotDefined(f'failed to convert {num} to Decimal: {exc}')
raise NotDefined(f'failed to convert {num} to Decimal: {exc}') from exc

return str(s)

Expand Down Expand Up @@ -154,7 +154,7 @@ def split_version(version: str) -> tuple:
return tuple(tryint(x) for x in split('([^.]+)', version))


def is_greater_or_equal(num_a, num_b):
def is_greater_or_equal(num_a: str, num_b: str) -> bool:
"""
Check if the numbered string num_a >= num_b.
Expand Down Expand Up @@ -199,7 +199,7 @@ def convert_mb_to_b(size: Any) -> int:
try:
size = int(size)
except Exception as exc:
raise ValueError(f'cannot convert {size} to int: {exc}')
raise ValueError(f'cannot convert {size} to int: {exc}') from exc

return size * 1024 ** 2

Expand All @@ -215,7 +215,7 @@ def diff_lists(list_a: list, list_b: list) -> list:
return list(set(list_a) - set(list_b))


def bytes2human(num: Any, _format='%(value).1f %(symbol)s', symbols='customary'):
def bytes2human(num: Any, symbols: str = 'customary') -> str:
"""
Convert `num` bytes into a human-readable string based on format.
Expand Down Expand Up @@ -254,10 +254,11 @@ def bytes2human(num: Any, _format='%(value).1f %(symbol)s', symbols='customary')
'9.76562 K'
:param num: input number (Any)
:param _format: format string (str)
:param symbols: symbold string (str)
:return: human-readable string (str).
"""
_format = '%(value).1f %(symbol)s'

try:
number = int(num)
except ValueError as exc:
Expand All @@ -270,9 +271,10 @@ def bytes2human(num: Any, _format='%(value).1f %(symbol)s', symbols='customary')
prefix[s] = 1 << (i + 1) * 10
for symbol in reversed(symbols[1:]):
if number >= prefix[symbol]:
value = float(number) / prefix[symbol]
# value = float(number) / prefix[symbol]
return _format % locals()
return _format % dict(symbol=symbols[0], value=number)

return _format % {"symbol": symbols[0], "value": number}


def human2bytes(snumber: str, divider: Any = None) -> int:
Expand Down Expand Up @@ -322,7 +324,8 @@ def human2bytes(snumber: str, divider: Any = None) -> int:
:param snumber: number string (str)
:param divider: divider (Any)
:return: converted integer (int).
:return: converted integer (int)
:raises ValueError: for conversion error.
"""
init = snumber
num = ""
Expand All @@ -343,7 +346,7 @@ def human2bytes(snumber: str, divider: Any = None) -> int:
if len(letter) == 0:
letter = "B"

for name, sset in list(SYMBOLS.items()):
for _, sset in list(SYMBOLS.items()):
if letter in sset:
break
else:
Expand All @@ -365,3 +368,18 @@ def human2bytes(snumber: str, divider: Any = None) -> int:
raise exc

return ret


def convert_seconds_to_hours_minutes_seconds(seconds: int) -> tuple:
"""
Convert seconds to hours, minutes, and remaining seconds.
:param seconds: seconds (int)
:return: hours, minutes, remaining seconds (tuple).
"""
hours = seconds // 3600
remaining_seconds = seconds % 3600
minutes = remaining_seconds // 60
remaining_seconds %= 60

return hours, minutes, remaining_seconds

0 comments on commit fb50597

Please sign in to comment.