This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
import os
|
||||
import sys
|
||||
import warnings
|
||||
from datetime import datetime, timezone
|
||||
from datetime import datetime
|
||||
from importlib import import_module
|
||||
from typing import IO, TYPE_CHECKING, Any, List, Optional, cast
|
||||
|
||||
@@ -16,7 +16,6 @@ if TYPE_CHECKING:
|
||||
from types import ModuleType
|
||||
from typing import Protocol
|
||||
|
||||
from django.db.backends.base.base import BaseDatabaseWrapper
|
||||
from django.db.utils import ConnectionHandler
|
||||
|
||||
from celery.app.base import Celery
|
||||
@@ -79,9 +78,6 @@ class DjangoFixup:
|
||||
self._settings = symbol_by_name('django.conf:settings')
|
||||
self.app.loader.now = self.now
|
||||
|
||||
if not self.app._custom_task_cls_used:
|
||||
self.app.task_cls = 'celery.contrib.django.task:DjangoTask'
|
||||
|
||||
signals.import_modules.connect(self.on_import_modules)
|
||||
signals.worker_init.connect(self.on_worker_init)
|
||||
return self
|
||||
@@ -104,7 +100,7 @@ class DjangoFixup:
|
||||
self.worker_fixup.install()
|
||||
|
||||
def now(self, utc: bool = False) -> datetime:
|
||||
return datetime.now(timezone.utc) if utc else self._now()
|
||||
return datetime.utcnow() if utc else self._now()
|
||||
|
||||
def autodiscover_tasks(self) -> List[str]:
|
||||
from django.apps import apps
|
||||
@@ -165,16 +161,15 @@ class DjangoWorkerFixup:
|
||||
# network IO that close() might cause.
|
||||
for c in self._db.connections.all():
|
||||
if c and c.connection:
|
||||
self._maybe_close_db_fd(c)
|
||||
self._maybe_close_db_fd(c.connection)
|
||||
|
||||
# use the _ version to avoid DB_REUSE preventing the conn.close() call
|
||||
self._close_database(force=True)
|
||||
self.close_cache()
|
||||
|
||||
def _maybe_close_db_fd(self, c: "BaseDatabaseWrapper") -> None:
|
||||
def _maybe_close_db_fd(self, fd: IO) -> None:
|
||||
try:
|
||||
with c.wrap_database_errors:
|
||||
_maybe_close_fd(c.connection)
|
||||
_maybe_close_fd(fd)
|
||||
except self.interface_errors:
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user