Skip to content

Commit

Permalink
Fix: func reference in admin (Koed00#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
GDay authored Nov 5, 2022
1 parent f62bd7b commit 6f19b3d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
15 changes: 1 addition & 14 deletions django_q/cluster.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Standard
import ast
import inspect
import pydoc
import signal
import socket
Expand Down Expand Up @@ -44,7 +43,7 @@
from django_q.signing import BadSignature, SignedPackage
from django_q.status import Stat, Status

from .utils import add_months, add_years
from .utils import add_months, add_years, get_func_repr


class Cluster:
Expand Down Expand Up @@ -456,18 +455,6 @@ def worker(
break
logger.info(_(f"{proc_name} stopped doing work"))

def get_func_repr(func):
# convert func to string
if inspect.isfunction(func):
return f"{func.__module__}.{func.__name__}"
elif inspect.ismethod(func) and hasattr(func.__self__, '__name__'):
return (
f"{func.__self__.__module__}."
f"{func.__self__.__name__}.{func.__name__}"
)
else:
return str(func)

def save_task(task, broker: Broker):
"""
Saves the task package to Django or the cache
Expand Down
3 changes: 2 additions & 1 deletion django_q/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# Local
from django_q.conf import croniter
from django_q.signing import SignedPackage
from .utils import get_func_repr


class Task(models.Model):
Expand Down Expand Up @@ -241,7 +242,7 @@ def task(self):
return SignedPackage.loads(self.payload)

def func(self):
return self.task()["func"]
return get_func_repr(self.task()["func"])

def task_id(self):
return self.task()["id"]
Expand Down
16 changes: 14 additions & 2 deletions django_q/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime
import inspect
from datetime import date
from django.utils.timezone import make_aware
import calendar

# credits: https://stackoverflow.com/a/4131114
Expand Down Expand Up @@ -28,3 +27,16 @@ def add_years(d, years):
new_date = d + (date(d.year + years, 3, 1) - date(d.year, 3, 1))
return d.replace(year=new_date.year, month=new_date.month, day=new_date.day)


def get_func_repr(func):
# convert func to string
if inspect.isfunction(func):
return f"{func.__module__}.{func.__name__}"
elif inspect.ismethod(func) and hasattr(func.__self__, '__name__'):
return (
f"{func.__self__.__module__}."
f"{func.__self__.__name__}.{func.__name__}"
)
else:
return str(func)

0 comments on commit 6f19b3d

Please sign in to comment.