Skip to content

Commit

Permalink
sleeper: fix logger
Browse files Browse the repository at this point in the history
  • Loading branch information
naisanzaa committed Nov 7, 2023
1 parent b14d03b commit 86b1136
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions automon/helpers/sleeper.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import time
import random

from automon.log import Logging
from automon.log import logger

log = Logging(name='Sleeper', level=Logging.INFO)
log = logger.logging.getLogger(__name__)
log.setLevel(logger.INFO)


class Sleeper:
Expand All @@ -15,18 +16,18 @@ def seconds(caller: object or str, seconds: int) -> time.sleep:
sleep = seconds
if sleep < 2:
log.debug(f'[{Sleeper.seconds.__name__}] '
f'[{caller}] sleeping for {sleep} second')
f'[{caller}] sleeping for {sleep} second')
else:
log.debug(f'[{Sleeper.seconds.__name__}] '
f'[{caller}] sleeping for {sleep} seconds')
f'[{caller}] sleeping for {sleep} seconds')
return time.sleep(sleep)

@staticmethod
def minute(caller: object or str, sleep: int = 60) -> time.sleep:
"""Sleep for a minute"""

log.debug(f'[{Sleeper.minute.__name__}] '
f'[{caller}] sleeping for {sleep} seconds')
f'[{caller}] sleeping for {sleep} seconds')
return time.sleep(sleep)

@staticmethod
Expand All @@ -36,7 +37,7 @@ def within_a_minute(caller, sleep: int = None):
sleep = sleep if isinstance(sleep, int) else \
random.choice(range(1, 1 * 60))
log.debug(f'[{Sleeper.within_a_minute.__name__}] '
f'[{caller}] sleeping for {sleep} seconds')
f'[{caller}] sleeping for {sleep} seconds')
return time.sleep(sleep)

@staticmethod
Expand All @@ -45,7 +46,7 @@ def minutes(caller, minutes: int):

sleep = minutes * 60
log.debug(f'[{Sleeper.minutes.__name__}] '
f'[{caller}] sleeping for {sleep} minutes')
f'[{caller}] sleeping for {sleep} minutes')
return time.sleep(sleep)

@staticmethod
Expand All @@ -55,7 +56,7 @@ def hour(caller, hour: int = 1):
sleep = hour if not hour else random.choice(
range(1, hour * 60 * 60))
log.debug(f'[{Sleeper.hour.__name__}] '
f'[{caller}] sleeping for {sleep} seconds')
f'[{caller}] sleeping for {sleep} seconds')
return time.sleep(sleep)

@staticmethod
Expand All @@ -64,7 +65,7 @@ def hours(caller, hours):

sleep = hours * 60 * 60
log.debug(f'[{Sleeper.hours.__name__}] '
f'[{caller}] sleeping for {hours} hours')
f'[{caller}] sleeping for {hours} hours')
return time.sleep(sleep)

@staticmethod
Expand All @@ -74,7 +75,7 @@ def day(caller, hours: int = 24):
sleep = hours if not hours else random.choice(
range(1, hours * 60 * 60))
log.debug(f'[{Sleeper.day.__name__}] '
f'[{caller}] sleeping for {sleep} seconds')
f'[{caller}] sleeping for {sleep} seconds')
return time.sleep(sleep)

@staticmethod
Expand All @@ -83,7 +84,7 @@ def daily(caller, hours: int = 24):

sleep = hours if not hours else hours * 60 * 60
log.debug(f'[{Sleeper.daily.__name__}] '
f'[{caller}] sleeping for {sleep} seconds')
f'[{caller}] sleeping for {sleep} seconds')
return time.sleep(sleep)

@staticmethod
Expand All @@ -93,5 +94,5 @@ def time_range(caller, seconds: int):
sleep = seconds if not seconds else random.choice(
range(1, seconds))
log.debug(f'[{Sleeper.time_range.__name__}] '
f'[{caller}] sleeping for {sleep} seconds')
f'[{caller}] sleeping for {sleep} seconds')
return time.sleep(sleep)

0 comments on commit 86b1136

Please sign in to comment.