Merge pull request #765 from tcely/patch-3

Upgrade to 1.2.8 for Django 5 support
This commit is contained in:
meeb 2025-02-24 21:43:14 +11:00 committed by GitHub
commit a57b92b5b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 14 deletions

View File

@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v4
- name: Install Python ${{ matrix.python-version }}

View File

@ -7,7 +7,7 @@ verify_ssl = true
autopep8 = "*"
[packages]
django = "~=3.2"
django = "*"
django-sass-processor = "*"
libsass = "*"
pillow = "*"
@ -15,7 +15,7 @@ whitenoise = "*"
gunicorn = "*"
django-compressor = "*"
httptools = "*"
django-background-tasks = "==1.2.5"
django-background-tasks = ">=1.2.8"
django-basicauth = "*"
psycopg2-binary = "*"
mysqlclient = "*"

View File

@ -6,8 +6,8 @@ import logging
import os
import traceback
from compat import StringIO
from compat.models import GenericForeignKey
from io import StringIO
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.db.models import Q
@ -50,14 +50,15 @@ class TaskManager(models.Manager):
if queue:
qs = qs.filter(queue=queue)
ready = qs.filter(run_at__lte=now, failed_at=None)
_priority_ordering = '{}priority'.format(app_settings.BACKGROUND_TASK_PRIORITY_ORDERING)
_priority_ordering = '{}priority'.format(
app_settings.BACKGROUND_TASK_PRIORITY_ORDERING)
ready = ready.order_by(_priority_ordering, 'run_at')
if app_settings.BACKGROUND_TASK_RUN_ASYNC:
currently_failed = self.failed().count()
currently_locked = self.locked(now).count()
count = app_settings.BACKGROUND_TASK_ASYNC_THREADS - \
(currently_locked - currently_failed)
(currently_locked - currently_failed)
if count > 0:
ready = ready[:count]
else:
@ -102,7 +103,8 @@ class TaskManager(models.Manager):
s = "%s%s" % (task_name, task_params)
task_hash = sha1(s.encode('utf-8')).hexdigest()
if remove_existing_tasks:
Task.objects.filter(task_hash=task_hash, locked_at__isnull=True).delete()
Task.objects.filter(task_hash=task_hash,
locked_at__isnull=True).delete()
return Task(task_name=task_name,
task_params=task_params,
task_hash=task_hash,
@ -251,13 +253,14 @@ class Task(models.Model):
self.failed_at = timezone.now()
logger.warning('Marking task %s as failed', self)
completed = self.create_completed_task()
task_failed.send(sender=self.__class__, task_id=self.id, completed_task=completed)
task_failed.send(sender=self.__class__,
task_id=self.id, completed_task=completed)
self.delete()
else:
backoff = timedelta(seconds=(self.attempts ** 4) + 5)
self.run_at = timezone.now() + backoff
logger.warning('Rescheduling task %s for %s later at %s', self,
backoff, self.run_at)
backoff, self.run_at)
task_rescheduled.send(sender=self.__class__, task=self)
self.locked_by = None
self.locked_at = None
@ -330,9 +333,6 @@ class Task(models.Model):
db_table = 'background_task'
class CompletedTaskQuerySet(models.QuerySet):
def created_by(self, creator):
@ -389,7 +389,8 @@ class CompletedTask(models.Model):
# when the task should be run
run_at = models.DateTimeField(db_index=True)
repeat = models.BigIntegerField(choices=Task.REPEAT_CHOICES, default=Task.NEVER)
repeat = models.BigIntegerField(
choices=Task.REPEAT_CHOICES, default=Task.NEVER)
repeat_until = models.DateTimeField(null=True, blank=True)
# the "name" of the queue this is to be run on