mirror of
https://github.com/django-q2/django-q2.git
synced 2026-10-08 05:18:12 +08:00
Workaround for Travis
Travis doesn't support cpu affinity in their virtuals so I've added a setting TESTING that will bypass the actual affinity setting, but will still cover most of the code. Might be useful for future workarounds.
This commit is contained in:
+4
-2
@@ -473,12 +473,13 @@ def scheduler(list_key=Conf.Q_LIST):
|
|||||||
s.save()
|
s.save()
|
||||||
|
|
||||||
|
|
||||||
def set_cpu_affinity(n, process_ids):
|
def set_cpu_affinity(n, process_ids, actual=not Conf.TESTING):
|
||||||
"""
|
"""
|
||||||
Sets the cpu affinity for the supplied processes.
|
Sets the cpu affinity for the supplied processes.
|
||||||
Requires the optional psutil module.
|
Requires the optional psutil module.
|
||||||
:param int n:
|
:param int n:
|
||||||
:param list process_ids: a list of pids
|
:param list process_ids: a list of pids
|
||||||
|
:param bool actual: Test workaround for Travis not supporting cpu affinity
|
||||||
"""
|
"""
|
||||||
# check if we have the psutil module
|
# check if we have the psutil module
|
||||||
if not psutil:
|
if not psutil:
|
||||||
@@ -499,5 +500,6 @@ def set_cpu_affinity(n, process_ids):
|
|||||||
index += 1
|
index += 1
|
||||||
if psutil.pid_exists(pid):
|
if psutil.pid_exists(pid):
|
||||||
p = psutil.Process(pid)
|
p = psutil.Process(pid)
|
||||||
p.cpu_affinity(affinity)
|
if actual:
|
||||||
|
p.cpu_affinity(affinity)
|
||||||
logger.info('{} will use cpu {}'.format(pid, affinity))
|
logger.info('{} will use cpu {}'.format(pid, affinity))
|
||||||
@@ -67,6 +67,9 @@ class Conf(object):
|
|||||||
STOPPED = _('Stopped')
|
STOPPED = _('Stopped')
|
||||||
STOPPING = _('Stopping')
|
STOPPING = _('Stopping')
|
||||||
|
|
||||||
|
# to manage workarounds during testing
|
||||||
|
TESTING = conf.get('testings', False)
|
||||||
|
|
||||||
|
|
||||||
# logger
|
# logger
|
||||||
logger = logging.getLogger('django-q')
|
logger = logging.getLogger('django-q')
|
||||||
|
|||||||
@@ -103,4 +103,5 @@ STATIC_URL = '/static/'
|
|||||||
|
|
||||||
# Django Q specific
|
# Django Q specific
|
||||||
Q_CLUSTER = {'name': 'django_q_test',
|
Q_CLUSTER = {'name': 'django_q_test',
|
||||||
'cpu_affinity': 0}
|
'cpu_affinity': 1,
|
||||||
|
'testing': True}
|
||||||
|
|||||||
Reference in New Issue
Block a user