Skip to content

Commit

Permalink
Funcionalidad y configuracion comun #51 #52
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosrmartin committed Jun 2, 2024
1 parent 208109e commit ef9c395
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
Empty file added mass/__init__.py
Empty file.
39 changes: 39 additions & 0 deletions mass/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import logging
import signal

NGINX = "NGINX"
HTTPD = "HTTPD"
PROXY = "PROXY"

PORT = {
NGINX: "8009",
HTTPD: "8008",
PROXY: "80"
}

# Logger configuration
logging.basicConfig(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)

# Get a specific logger for the package
logger = logging.getLogger('MASS')

def configure_logging(level=logging.INFO):
logger.setLevel(level)
for handler in logger.handlers:
handler.setLevel(level)

_shutdown = False

def get_shutdown():
return _shutdown


def signal_handler(sig, frame):
global _shutdown
if not _shutdown:
logger.info("\nShutting down...")
_shutdown = True

signal.signal(signal.SIGINT, signal_handler)
26 changes: 26 additions & 0 deletions mass/decorators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import time
import functools
from .config import logger

def timing_decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
start_time = time.time()
result = func(*args, **kwargs)
end_time = time.time()
elapsed_time = end_time - start_time
logger.debug(f"Method {func.__name__} execution took: {elapsed_time:.6f} seconds.")
return result
return wrapper

def apply_timing_to_methods(decorator):
def decorate(cls):
for attr in dir(cls):
if attr.startswith("__") and attr.endswith("__"):
continue
original_method = getattr(cls, attr)
if callable(original_method):
decorated_method = decorator(original_method)
setattr(cls, attr, decorated_method)
return cls
return decorate

0 comments on commit ef9c395

Please sign in to comment.