From a5580c75a199f276af6639d159a9d7ef9958d663 Mon Sep 17 00:00:00 2001 From: Ilan Date: Wed, 15 Jul 2015 22:17:13 +0200 Subject: [PATCH] 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. --- django_q/cluster.py | 6 ++++-- django_q/conf.py | 3 +++ django_q/tests/settings.py | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/django_q/cluster.py b/django_q/cluster.py index 10e4f55..3470ccb 100644 --- a/django_q/cluster.py +++ b/django_q/cluster.py @@ -473,12 +473,13 @@ def scheduler(list_key=Conf.Q_LIST): 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. Requires the optional psutil module. :param int n: :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 if not psutil: @@ -499,5 +500,6 @@ def set_cpu_affinity(n, process_ids): index += 1 if psutil.pid_exists(pid): p = psutil.Process(pid) - p.cpu_affinity(affinity) + if actual: + p.cpu_affinity(affinity) logger.info('{} will use cpu {}'.format(pid, affinity)) \ No newline at end of file diff --git a/django_q/conf.py b/django_q/conf.py index 9606674..65f44c3 100644 --- a/django_q/conf.py +++ b/django_q/conf.py @@ -67,6 +67,9 @@ class Conf(object): STOPPED = _('Stopped') STOPPING = _('Stopping') + # to manage workarounds during testing + TESTING = conf.get('testings', False) + # logger logger = logging.getLogger('django-q') diff --git a/django_q/tests/settings.py b/django_q/tests/settings.py index 4cfc90e..7999a78 100644 --- a/django_q/tests/settings.py +++ b/django_q/tests/settings.py @@ -103,4 +103,5 @@ STATIC_URL = '/static/' # Django Q specific Q_CLUSTER = {'name': 'django_q_test', - 'cpu_affinity': 0} + 'cpu_affinity': 1, + 'testing': True}