mirror of
https://github.com/django-q2/django-q2.git
synced 2026-10-09 07:08:11 +08:00
#40 qsize not implemented
This commit is contained in:
+1
-1
@@ -149,7 +149,7 @@ class Sentinel(object):
|
|||||||
if not self.start_event.is_set() and not self.stop_event.is_set():
|
if not self.start_event.is_set() and not self.stop_event.is_set():
|
||||||
return Conf.STARTING
|
return Conf.STARTING
|
||||||
elif self.start_event.is_set() and not self.stop_event.is_set():
|
elif self.start_event.is_set() and not self.stop_event.is_set():
|
||||||
if self.result_queue.qsize() == 0 and self.task_queue.qsize() == 0:
|
if Conf.QSIZE and self.result_queue.qsize() == 0 and self.task_queue.qsize() == 0:
|
||||||
return Conf.IDLE
|
return Conf.IDLE
|
||||||
return Conf.WORKING
|
return Conf.WORKING
|
||||||
elif self.stop_event.is_set() and self.start_event.is_set():
|
elif self.stop_event.is_set() and self.start_event.is_set():
|
||||||
|
|||||||
+7
-1
@@ -1,6 +1,6 @@
|
|||||||
import logging
|
import logging
|
||||||
from signal import signal
|
from signal import signal
|
||||||
from multiprocessing import cpu_count
|
from multiprocessing import cpu_count, Queue
|
||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@@ -63,6 +63,12 @@ class Conf(object):
|
|||||||
# The redis stats key
|
# The redis stats key
|
||||||
Q_STAT = 'django_q:{}:cluster'.format(PREFIX)
|
Q_STAT = 'django_q:{}:cluster'.format(PREFIX)
|
||||||
|
|
||||||
|
# OSX doesn't implement qsize because of missing sem_getvalue()
|
||||||
|
try:
|
||||||
|
QSIZE = Queue().qsize == 0
|
||||||
|
except NotImplementedError:
|
||||||
|
QSIZE = False
|
||||||
|
|
||||||
# Getting the signal names
|
# Getting the signal names
|
||||||
SIGNAL_NAMES = dict((getattr(signal, n), n) for n in dir(signal) if n.startswith('SIG') and '_' not in n)
|
SIGNAL_NAMES = dict((getattr(signal, n), n) for n in dir(signal) if n.startswith('SIG') and '_' not in n)
|
||||||
|
|
||||||
|
|||||||
+5
-2
@@ -117,10 +117,13 @@ class Stat(Status):
|
|||||||
self.reincarnations = sentinel.reincarnations
|
self.reincarnations = sentinel.reincarnations
|
||||||
self.sentinel = sentinel.pid
|
self.sentinel = sentinel.pid
|
||||||
self.status = sentinel.status()
|
self.status = sentinel.status()
|
||||||
self.done_q_size = sentinel.result_queue.qsize()
|
self.done_q_size = 0
|
||||||
|
self.task_q_size = 0
|
||||||
|
if Conf.QSIZE:
|
||||||
|
self.done_q_size = sentinel.result_queue.qsize()
|
||||||
|
self.task_q_size = sentinel.task_queue.qsize()
|
||||||
if sentinel.monitor:
|
if sentinel.monitor:
|
||||||
self.monitor = sentinel.monitor.pid
|
self.monitor = sentinel.monitor.pid
|
||||||
self.task_q_size = sentinel.task_queue.qsize()
|
|
||||||
if sentinel.pusher:
|
if sentinel.pusher:
|
||||||
self.pusher = sentinel.pusher.pid
|
self.pusher = sentinel.pusher.pid
|
||||||
self.workers = [w.pid for w in sentinel.pool]
|
self.workers = [w.pid for w in sentinel.pool]
|
||||||
|
|||||||
@@ -55,7 +55,8 @@ def test_cluster_initial(r):
|
|||||||
assert c.is_starting is False
|
assert c.is_starting is False
|
||||||
sleep(0.5)
|
sleep(0.5)
|
||||||
stat = c.stat
|
stat = c.stat
|
||||||
assert stat.status == Conf.IDLE
|
if Conf.QSIZE:
|
||||||
|
assert stat.status == Conf.IDLE
|
||||||
assert c.stop() is True
|
assert c.stop() is True
|
||||||
assert c.sentinel.is_alive() is False
|
assert c.sentinel.is_alive() is False
|
||||||
assert c.has_stopped
|
assert c.has_stopped
|
||||||
|
|||||||
Reference in New Issue
Block a user