mirror of
https://github.com/dkmstr/openuds.git
synced 2025-02-03 13:47:14 +03:00
Several minor fixes
This commit is contained in:
parent
2096ad085a
commit
500347d878
@ -60,10 +60,10 @@ class Job(Environmentable):
|
||||
'''
|
||||
if cls.frecuency_cfg is not None:
|
||||
try:
|
||||
logger.debug('Setting frecuency from DB setting for {}'.format(cls))
|
||||
cls.frecuency = cls.frecuency_cfg.getInt(force=True)
|
||||
logger.debug('Setting frequency from DB setting for {} to {}'.format(cls, cls.frecuency))
|
||||
except Exception as e:
|
||||
logger.error('Error setting default frecuency for {}. left as default {}'.format(cls, cls.frecuency))
|
||||
logger.error('Error setting default frequency for {} (){}. Got default value of {}'.format(cls, e, cls.frecuency))
|
||||
|
||||
def execute(self):
|
||||
try:
|
||||
|
@ -72,6 +72,7 @@ class JobsFactory(object):
|
||||
workers.initialize()
|
||||
for name, type_ in self._jobs.iteritems():
|
||||
try:
|
||||
type_.setup()
|
||||
# We use database server datetime
|
||||
now = getSqlDatetime()
|
||||
next_ = now
|
||||
|
@ -36,7 +36,7 @@ from django.utils.translation import ugettext_noop as _
|
||||
from uds.core.util.State import State
|
||||
from uds.core import Module
|
||||
|
||||
__updated__ = '2014-09-25'
|
||||
__updated__ = '2014-11-27'
|
||||
|
||||
STORAGE_KEY = 'osmk'
|
||||
|
||||
@ -55,8 +55,8 @@ class OSManager(Module):
|
||||
typeDescription = _('Base Manager')
|
||||
iconFile = 'osmanager.png'
|
||||
|
||||
# If true, this os manager will be invoked with every user service assigned, but not used from time to time
|
||||
# Time is defined as a global config
|
||||
# If true, this os manager will be invoked with every user service assigned, but not used
|
||||
# The interval is defined as a global config
|
||||
processUnusedMachines = False
|
||||
|
||||
def __init__(self, environment, values):
|
||||
|
@ -35,7 +35,6 @@ from django.conf import settings
|
||||
from django.apps import apps
|
||||
from uds.models import Config as dbConfig
|
||||
from uds.core.managers.CryptoManager import CryptoManager
|
||||
import traceback
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -77,8 +76,6 @@ class Config(object):
|
||||
# From Django 1.7, DB can only be accessed AFTER all apps are initialized, curious at least.. :)
|
||||
if apps.ready is True and GlobalConfig.initDone is False:
|
||||
logger.debug('Initializing configuration & updating db values')
|
||||
for v in traceback.format_stack():
|
||||
logger.debug(v)
|
||||
GlobalConfig.initialize()
|
||||
|
||||
try:
|
||||
|
@ -53,18 +53,17 @@ class AssignedAndUnused(Job):
|
||||
super(AssignedAndUnused, self).__init__(environment)
|
||||
|
||||
def run(self):
|
||||
since_state = getSqlDatetime() - timedelta(seconds=GlobalConfig.CHECK_UNUSED_TIME.getInt())
|
||||
since_state = getSqlDatetime() - timedelta(seconds=self.frecuency)
|
||||
for ds in DeployedService.objects.all():
|
||||
# If do not needs os manager, this is
|
||||
if ds.osmanager is not None:
|
||||
osm = ds.osmanager.getInstance()
|
||||
if osm.processUnusedMachines is True:
|
||||
logger.debug('Processing unused services for {0}'.format(osm))
|
||||
logger.debug('Processing unused services for {}, {}'.format(ds, ds.osmanager))
|
||||
for us in ds.assignedUserServices().filter(in_use=False, state_date__lt=since_state, state=State.USABLE, os_state=State.USABLE):
|
||||
logger.debug('Found unused assigned service {0}'.format(us))
|
||||
osm.processUnused(us)
|
||||
else: # No os manager, simply remove unused services in specified time
|
||||
with transaction.atomic():
|
||||
for us in ds.assignedUserServices().filter(in_use=False, state_date__lt=since_state, state=State.USABLE, os_state=State.USABLE):
|
||||
logger.debug('Found unused assigned service {0}'.format(us))
|
||||
us.remove()
|
||||
for us in ds.assignedUserServices().filter(in_use=False, state_date__lt=since_state, state=State.USABLE, os_state=State.USABLE):
|
||||
logger.debug('Found unused assigned service {0}'.format(us))
|
||||
us.remove()
|
||||
|
@ -54,5 +54,4 @@ def initialize():
|
||||
for cls in p.__subclasses__():
|
||||
# Limit to autoregister just workers jobs inside this module
|
||||
if cls.__module__[0:16] == 'uds.core.workers':
|
||||
cls.setup()
|
||||
TaskManager.registerJob(cls)
|
||||
|
Loading…
x
Reference in New Issue
Block a user