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

Feature: save_limit per task group #508

Closed
Closed
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
3 changes: 3 additions & 0 deletions django_q/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,9 @@ def save_task(task, broker: Broker):
try:
if task["success"] and 0 < Conf.SAVE_LIMIT <= Success.objects.count():
Success.objects.last().delete()
elif task["success"] and 0 < Conf.SAVE_LIMIT_PER_GROUP <= Success.objects.filter(group=task['group']).count():
Success.objects.filter(group=task['group']).last().delete()

# check if this task has previous results
if Task.objects.filter(id=task["id"], name=task["name"]).exists():
existing_task = Task.objects.get(id=task["id"], name=task["name"])
Expand Down
2 changes: 2 additions & 0 deletions django_q/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ class Conf:
# Failures are always saved
SAVE_LIMIT = conf.get("save_limit", 250)

SAVE_LIMIT_PER_GROUP = conf.get("save_limit_per_group", 0)

# Guard loop sleep in seconds. Should be between 0 and 60 seconds.
GUARD_CYCLE = conf.get("guard_cycle", 0.5)

Expand Down