Skip to content

Commit

Permalink
More consistent log statements
Browse files Browse the repository at this point in the history
  • Loading branch information
simonhugosson committed Dec 12, 2022
1 parent faba0f9 commit a4476cb
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions django_leek/server.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
from datetime import datetime
from sys import platform
import json
import logging
import socketserver
import multiprocessing
import queue
import socketserver
import threading
from sys import platform

from .helpers import load_task
from . import helpers
from django.utils import timezone
import django
from django.utils import timezone

from . import helpers
from .helpers import load_task

log = logging.getLogger(__name__)


def target(queue):
django.setup()
log.info('Worker Starts')
log.info("Worker Starts")
while True:
task_id = queue.get()
if task_id is None:
return

log.info('running task...')
log.info("running task...")

# workaround to solve problems with django + psycopg2
# solution found here: https://stackoverflow.com/a/36580629/10385696
django.db.connection.close()

task = load_task(task_id=task_id)
if task.finished():
print('skipping ', task_id, "as it is already finished")
log.info("skipping %s as it is already finished", task_id)
continue

pickled_task = helpers.unpack(task.pickled_task)
Expand All @@ -44,7 +43,7 @@ def target(queue):
task.pickled_return = helpers.serialize(return_value)
task.save()

log.info('...successfully')
log.info("...successfully")
except Exception as e:
log.exception("...task failed")
task.finished_at = timezone.now()
Expand Down Expand Up @@ -76,7 +75,7 @@ def handle(self):
data = self.request.recv(5000).strip()

# assume a serialized task
log.info('Got a task')
log.info("Got a task")
task_id = None
try:
task_id = int(data.decode())
Expand All @@ -90,7 +89,7 @@ def handle(self):
pool = self.pools.get(pool_name)
if pool is None or not pool.worker.is_alive():
# Spawn new pool
log.info('Spawning new pool: {}'.format(pool_name))
log.info("Spawning new pool: {}".format(pool_name))
self.pools[pool_name] = Pool()
self.pools[pool_name].worker.start()

Expand All @@ -110,5 +109,5 @@ def handle(self):
@staticmethod
def stop():
for name, pool in TaskSocketServer.pools.items():
print('Stopping pool:', name)
log.info("Stopping pool: %s", name)
pool.stop()

0 comments on commit a4476cb

Please sign in to comment.