From 8822e7d409c3e9a01f713d765aae7004a6745cfb Mon Sep 17 00:00:00 2001 From: Stan Triepels <1939656+GDay@users.noreply.github.com> Date: Thu, 20 Oct 2022 15:17:44 +0200 Subject: [PATCH] Remove funding file, add docker/compose for development project and fix (#18) task names in logs --- .github/FUNDING.yml | 3 --- Dockerfile | 8 ++++++++ django_q/cluster.py | 15 ++++++++------- web-docker-compose.yaml | 11 +++++++++++ 4 files changed, 27 insertions(+), 10 deletions(-) delete mode 100644 .github/FUNDING.yml create mode 100644 Dockerfile create mode 100644 web-docker-compose.yaml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml deleted file mode 100644 index e21bb1d..0000000 --- a/.github/FUNDING.yml +++ /dev/null @@ -1,3 +0,0 @@ -# These are supported funding model platforms - -github: [koed00] diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..34bd734 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM python:3.9 + +ENV PYTHONUNBUFFERED 1 +RUN mkdir -p /app +WORKDIR /app +COPY . . +RUN pip install django blessed django-picklefield + diff --git a/django_q/cluster.py b/django_q/cluster.py index df4afb4..8a9046a 100644 --- a/django_q/cluster.py +++ b/django_q/cluster.py @@ -390,13 +390,13 @@ def monitor(result_queue: Queue, broker: Broker = None): # signal execution done post_execute.send(sender="django_q", task=task) # log the result - info_name = f"{task['name']} ({task['func']})" + info_name = get_func_repr(task['func']) if task["success"]: # log success - logger.info(_(f"Processed [{info_name}]")) + logger.info(_(f"Processed {info_name} ({task['name']})")) else: # log failure - logger.error(_(f"Failed [{info_name}] - {task['result']}")) + logger.error(_(f"Failed {info_name} ({task['name']}) - {task['result']}")) logger.info(_(f"{name} stopped monitoring results")) @@ -422,8 +422,8 @@ def worker( task_count += 1 # Get the function from the task func = task["func"] - func_name = func.__name__ if hasattr(func, "__name__") else str(func) - logger.info(_(f'{proc_name} processing [{task["name"]}({func_name})]')) + func_name = get_func_repr(func) + logger.info(_(f'{proc_name} processing {func_name} ({task["name"]})')) f = task["func"] # if it's not an instance try to get it from the string if not callable(task["func"]): @@ -460,12 +460,13 @@ def get_func_repr(func): # convert func to string if inspect.isfunction(func): return f"{func.__module__}.{func.__name__}" - elif inspect.ismethod(func): + elif inspect.ismethod(func) and hasattr(func.__self__, '__name__'): return ( f"{func.__self__.__module__}." f"{func.__self__.__name__}.{func.__name__}" ) - return func + else: + return str(func) def save_task(task, broker: Broker): """ diff --git a/web-docker-compose.yaml b/web-docker-compose.yaml new file mode 100644 index 0000000..19548a3 --- /dev/null +++ b/web-docker-compose.yaml @@ -0,0 +1,11 @@ +version: '3' + +services: + web: + restart: always + command: python manage.py runserver 0.0.0.0:8000 + ports: + - "127.0.0.1:8000:8000" + build: . + volumes: + - .:/app