From 44e6a3b50c9de444424051a80263e53900111116 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez=20Garc=C3=ADa?= Date: Tue, 25 Nov 2014 11:53:01 +0100 Subject: [PATCH] * Fixed Properties to be unique for every user service, not globally * Minor adjunst to StuckCleaner --- server/src/uds/core/util/Config.py | 15 ++++++--------- server/src/uds/core/workers/StuckCleaner.py | 6 +++--- .../uds/migrations/0008_userserviceproperty.py | 6 +++++- server/src/uds/models/UserServiceProperty.py | 5 +++-- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/server/src/uds/core/util/Config.py b/server/src/uds/core/util/Config.py index 0d007ae92..8bdb495ae 100644 --- a/server/src/uds/core/util/Config.py +++ b/server/src/uds/core/util/Config.py @@ -144,16 +144,13 @@ class Config(object): ''' logger.debug('Saving config {0}.{1} as {2}'.format(self._section.name(), self._key, value)) try: - if dbConfig.objects.filter(section=self._section.name(), key=self._key).update(value=value, crypt=self._crypt, long=self._longText, field_type=self._type) == 0: # @UndefinedVariable - raise Exception() # Do not exists, create a new one + obj, _ = dbConfig.objects.get_or_create(section=self._section.name(), key=self._key) # @UndefinedVariable + obj.value, obj.crypt, obj.long, obj.field_type = value, self._crypt, self._longText, self._type + obj.save() except Exception: - logger.exception('Exception 2') - try: - dbConfig.objects.create(section=self._section.name(), key=self._key, value=value, crypt=self._crypt, long=self._longText, field_type=self._type) # @UndefinedVariable - except Exception: - logger.exception('Exception') - # Probably a migration issue, just ignore it - logger.info("Could not save configuration key {0}.{1}".format(self._section.name(), self._key)) + logger.exception('Exception') + # Probably a migration issue, just ignore it + logger.info("Could not save configuration key {0}.{1}".format(self._section.name(), self._key)) class _Section(object): def __init__(self, sectionName): diff --git a/server/src/uds/core/workers/StuckCleaner.py b/server/src/uds/core/workers/StuckCleaner.py index 2b41f91bb..cc527569a 100644 --- a/server/src/uds/core/workers/StuckCleaner.py +++ b/server/src/uds/core/workers/StuckCleaner.py @@ -41,7 +41,7 @@ import logging logger = logging.getLogger(__name__) -MAX_STUCK_TIME = 3600 * 24 * 7 # At most 7 days "Stuck", not configurable (there is no need to) +MAX_STUCK_TIME = 3600 * 24 * 2 # At most 2 days "Stuck", not configurable (there is no need to) class StuckCleaner(Job): @@ -49,8 +49,8 @@ class StuckCleaner(Job): Kaputen Cleaner is very similar to Hanged Cleaner, at start, almost a copy We keep it in a new place to "control" more specific thins ''' - frecuency = MAX_STUCK_TIME / 2 - friendly_name = 'Stuck States checker' + frecuency = 3600 * 24 # Executes Once a day + friendly_name = 'Stuck States cleaner' def __init__(self, environment): super(StuckCleaner, self).__init__(environment) diff --git a/server/src/uds/migrations/0008_userserviceproperty.py b/server/src/uds/migrations/0008_userserviceproperty.py index bc2db586a..1dd05fe8f 100644 --- a/server/src/uds/migrations/0008_userserviceproperty.py +++ b/server/src/uds/migrations/0008_userserviceproperty.py @@ -15,7 +15,7 @@ class Migration(migrations.Migration): name='UserServiceProperty', fields=[ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), - ('name', models.CharField(unique=True, max_length=128, db_index=True)), + ('name', models.CharField(max_length=128, db_index=True)), ('value', models.TextField(default='')), ('user_service', models.ForeignKey(related_name='properties', to='uds.UserService')), ], @@ -24,4 +24,8 @@ class Migration(migrations.Migration): }, bases=(models.Model,), ), + migrations.AlterUniqueTogether( + name='userserviceproperty', + unique_together=set([('name', 'user_service')]), + ), ] diff --git a/server/src/uds/models/UserServiceProperty.py b/server/src/uds/models/UserServiceProperty.py index 8b80d3296..f156c6afd 100644 --- a/server/src/uds/models/UserServiceProperty.py +++ b/server/src/uds/models/UserServiceProperty.py @@ -35,7 +35,7 @@ from __future__ import unicode_literals -__updated__ = '2014-11-24' +__updated__ = '2014-11-25' from django.db import models from django.utils.encoding import python_2_unicode_compatible @@ -54,7 +54,7 @@ class UserServiceProperty(models.Model): Properties for User Service. The value field is a Text field, so we can put whatever we want in it ''' - name = models.CharField(max_length=128, db_index=True, unique=True) + name = models.CharField(max_length=128, db_index=True) value = models.TextField(default='') user_service = models.ForeignKey(UserService, on_delete=models.CASCADE, related_name='properties') @@ -63,6 +63,7 @@ class UserServiceProperty(models.Model): Meta class to declare default order and unique multiple field index ''' db_table = 'uds__user_service_property' + unique_together = (('name', 'user_service'),) app_label = 'uds' def __str__(self):