mirror of
https://github.com/django-q2/django-q2.git
synced 2026-09-20 03:18:07 +08:00
Fix: func reference in admin (#28)
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
# Standard
|
||||
import ast
|
||||
import inspect
|
||||
import pydoc
|
||||
import signal
|
||||
import socket
|
||||
@@ -44,7 +43,7 @@ from django_q.signals import post_execute, pre_execute
|
||||
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:
|
||||
@@ -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
|
||||
|
||||
@@ -15,6 +15,7 @@ from picklefield.fields import dbsafe_decode
|
||||
# Local
|
||||
from django_q.conf import croniter
|
||||
from django_q.signing import SignedPackage
|
||||
from .utils import get_func_repr
|
||||
|
||||
|
||||
class Task(models.Model):
|
||||
@@ -241,7 +242,7 @@ class OrmQ(models.Model):
|
||||
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"]
|
||||
|
||||
@@ -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
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user