Skip to content

Commit

Permalink
Merge pull request #9 from Volumental/fix/connection_closed
Browse files Browse the repository at this point in the history
Fix/connection closed
  • Loading branch information
vidstige authored Sep 26, 2018
2 parents f79998b + e06e712 commit 5511891
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 17 deletions.
1 change: 1 addition & 0 deletions django_leek/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions django_leek/helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import datetime
import pickle
import base64

Expand All @@ -7,7 +6,6 @@

def unpack(pickled_task):
new_task = pickle.loads(base64.b64decode(pickled_task))
#assert isinstance(new_task, partial)
return new_task


Expand Down
2 changes: 0 additions & 2 deletions django_leek/run_failed_tasks.py
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 2 additions & 2 deletions django_leek/tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import base64
import pickle
from unittest.mock import patch, MagicMock
import socketserver

Expand All @@ -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()
Expand Down
14 changes: 3 additions & 11 deletions django_leek/worker.py
Original file line number Diff line number Diff line change
@@ -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__)


Expand All @@ -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")
Expand Down

0 comments on commit 5511891

Please sign in to comment.