Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Admin Issue with Djongo DB Engine(Mongodb Engine) #683

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions django_q/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from django_q.conf import Conf, croniter
from django_q.models import Failure, OrmQ, Schedule, Success
from django_q.tasks import async_task

from django.db.models import Q
from django.db import connection

class TaskAdmin(admin.ModelAdmin):
"""model admin for success tasks."""
Expand All @@ -19,7 +20,14 @@ def has_add_permission(self, request):
def get_queryset(self, request):
"""Only show successes."""
qs = super(TaskAdmin, self).get_queryset(request)
return qs.filter(success=True)
if connection.vendor == "djongo":
ids=[]
for data in qs.filter(Q(attempt_count__gt = 0)):
if data.success:
ids.append(data.id)
return qs.filter(id__in = ids)
else:
return qs.filter(success=True)

search_fields = ("name", "func", "group")
readonly_fields = []
Expand Down
24 changes: 20 additions & 4 deletions django_q/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from django.utils import timezone
from django.utils.html import format_html
from django.utils.translation import gettext_lazy as _
from django.db import connection
from django.db.models import Q

# External
from picklefield import PickledObjectField
Expand Down Expand Up @@ -107,8 +109,15 @@ class Meta:

class SuccessManager(models.Manager):
def get_queryset(self):
return super(SuccessManager, self).get_queryset().filter(success=True)

qs = super(SuccessManager, self).get_queryset()
if connection.vendor == "djongo":
ids=[]
for data in qs.filter(Q(attempt_count__gte= 0)):
if data.success:
ids.append(data.id)
return qs.filter(id__in = ids)
else:
return qs.filter(success=True)

class Success(Task):
objects = SuccessManager()
Expand All @@ -123,8 +132,15 @@ class Meta:

class FailureManager(models.Manager):
def get_queryset(self):
return super(FailureManager, self).get_queryset().filter(success=False)

qs = super(FailureManager, self).get_queryset()
if connection.vendor == "djongo":
ids=[]
for data in qs.filter(Q(attempt_count__gte= 0)):
if not data.success:
ids.append(data.id)
return qs.filter(id__in = ids)
else:
return qs.filter(success=False)

class Failure(Task):
objects = FailureManager()
Expand Down
3 changes: 2 additions & 1 deletion django_q/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def get_process_mb(pid):
def monitor(run_once=False, broker=None):
if not broker:
broker = get_broker()

term = Terminal()
broker.ping()
with term.fullscreen(), term.hidden_cursor(), term.cbreak():
Expand Down Expand Up @@ -215,7 +216,7 @@ def info(broker=None):
tasks_per_day = last_tasks.count()
if tasks_per_day > 0:
# average execution time over the last 24 hours
if connection.vendor != "sqlite":
if connection.vendor != "sqlite" and connection.vendor != "djongo":
exec_time = last_tasks.aggregate(
time_taken=Sum(F("stopped") - F("started"))
)
Expand Down