diff --git a/django_leek/api.py b/django_leek/api.py index f615843..8d185ff 100644 --- a/django_leek/api.py +++ b/django_leek/api.py @@ -7,6 +7,7 @@ class Leek(object): def task(self, f, pool=None): pool_name = pool or f.__name__ + @wraps(f) def _offload(*args, **kwargs): return push_task_to_queue(f, pool_name=pool_name, *args, **kwargs) diff --git a/django_leek/helpers.py b/django_leek/helpers.py index 70d8253..f7cd175 100644 --- a/django_leek/helpers.py +++ b/django_leek/helpers.py @@ -1,4 +1,3 @@ -import datetime import pickle import base64 @@ -7,7 +6,6 @@ def unpack(pickled_task): new_task = pickle.loads(base64.b64decode(pickled_task)) - #assert isinstance(new_task, partial) return new_task diff --git a/django_leek/run_failed_tasks.py b/django_leek/run_failed_tasks.py index b7a3ef6..ae52612 100644 --- a/django_leek/run_failed_tasks.py +++ b/django_leek/run_failed_tasks.py @@ -1,8 +1,6 @@ import pickle import base64 import os -import sys - # environ settings variable, should be the same as in manage.py os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings") os.environ["DJANGO_SETTINGS_MODULE"] = "mysite.settings" diff --git a/django_leek/tests.py b/django_leek/tests.py index 9c6eb26..74526b0 100644 --- a/django_leek/tests.py +++ b/django_leek/tests.py @@ -1,5 +1,3 @@ -import base64 -import pickle from unittest.mock import patch, MagicMock import socketserver @@ -20,9 +18,11 @@ def test_keyboard_interrupt(self, serve_forever): serve_forever.side_effect = KeyboardInterrupt call_command('leek') + def f(): pass + class TestServer(TestCase): def setUp(self): self.request = MagicMock() diff --git a/django_leek/worker.py b/django_leek/worker.py index 304b555..cf651bf 100644 --- a/django_leek/worker.py +++ b/django_leek/worker.py @@ -1,18 +1,8 @@ # Based on the Worker class from Python in a nutshell, by Alex Martelli import logging -import os -import sys -import threading -import queue - import django - -from . import settings -from . import helpers - - log = logging.getLogger(__name__) @@ -29,7 +19,9 @@ def target(queue): log.info('running task...') task() - #helpers.save_task_success(task) + # workaround to solve problems with django + psycopg2 + # solution found here: https://stackoverflow.com/a/36580629/10385696 + django.db.connection.close() log.info('...successfully') except Exception as e: log.exception("...task failed")