1
0
mirror of https://github.com/dkmstr/openuds.git synced 2024-12-22 13:34:04 +03:00

* Done some refactoring over uds.core.jobs

* Added method to model Authenticator so we can check if it is of a type
This commit is contained in:
Adolfo Gómez 2012-07-30 02:30:46 +00:00
parent 6000d4f30c
commit 22d728a152
7 changed files with 59 additions and 12 deletions

View File

@ -47,6 +47,7 @@ encoding//src/uds/core/jobs/DelayedTaskRunner.py=utf-8
encoding//src/uds/core/jobs/Job.py=utf-8
encoding//src/uds/core/jobs/JobsFactory.py=utf-8
encoding//src/uds/core/jobs/Scheduler.py=utf-8
encoding//src/uds/core/jobs/__init__.py=utf-8
encoding//src/uds/core/managers/CryptoManager.py=utf-8
encoding//src/uds/core/managers/DownloadsManager.py=utf-8
encoding//src/uds/core/managers/PublicationManager.py=utf-8

View File

@ -32,7 +32,7 @@
'''
from uds.models import Scheduler
from uds.core.Environment import Environmentable
from uds.core import Environmentable
import logging
logger = logging.getLogger(__name__)

View File

@ -31,7 +31,6 @@
@author: Adolfo Gómez, dkmaster at dkmon dot com
'''
from datetime import timedelta
import logging
logger = logging.getLogger(__name__)
@ -51,28 +50,32 @@ class JobsFactory(object):
def jobs(self):
return self._jobs
def insert(self, name, type):
def insert(self, name, type_):
logger.debug('Inserting job {0} of type {1}'.format(name, type_))
try:
self._jobs[name] = type
self._jobs[name] = type_
except Exception, e:
logger.debug('Exception at insert in JobsFactory: {0}, {1}'.format(e.__class__, e))
def ensureJobsInDatabase(self):
from uds.models import Scheduler, getSqlDatetime, State
from uds.models import Scheduler, getSqlDatetime
from uds.core.util.State import State
try:
logger.debug('Ensuring that jobs are registered inside database')
for name, type in self._jobs.iteritems():
for name, type_ in self._jobs.iteritems():
try:
# We use database server datetime
now = getSqlDatetime()
next = now
job = Scheduler.objects.create(name = name, frecuency = type.frecuency, last_execution = now, next_execution = next, state = State.FOR_EXECUTE)
next_ = now
job = Scheduler.objects.create(name = name, frecuency = type_.frecuency, last_execution = now, next_execution = next_, state = State.FOR_EXECUTE)
except Exception: # already exists
logger.debug('Already added {0}'.format(name))
job = Scheduler.objects.get(name=name)
job.frecuency = type.frecuency
job.frecuency = type_.frecuency
job.save()
except Exception, e:
logger.debug('Exception at insert in JobsFactory: {0}, {1}'.format(e.__class__, e))
logger.debug('Exception at ensureJobsInDatabase in JobsFactory: {0}, {1}'.format(e.__class__, e))
def lookup(self, typeName):

View File

@ -103,6 +103,7 @@ class Scheduler(object):
job.delete()
transaction.commit()
return
logger.debug('Executing job:>{0}<'.format(job.name))
job.state = State.RUNNING
job.owner_server = self._hostname
job.last_execution = now
@ -131,6 +132,7 @@ class Scheduler(object):
def run(self):
# We ensure that the jobs are also in database so we can
logger.debug('Run Scheduler thread')
JobsFactory.factory().ensureJobsInDatabase()
self.releaseOwnShedules()
logger.debug("At loop")

View File

@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2012 Virtual Cable S.L.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# * Neither the name of Virtual Cable S.L. nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
'''
UDS jobs related modules
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
'''
from Job import Job
from DelayedTask import DelayedTask
def factory():
from JobsFactory import JobsFactory
return JobsFactory.factory()

View File

@ -87,8 +87,6 @@ class TaskManager(object):
JobsFactory.factory().insert('Publications Info Cleaner', PublicationInfoItemsCleaner)
JobsFactory.factory().insert('Publication Cleaner', PublicationCleaner)
JobsFactory.factory().insert('Utility Cache Cleaner', CacheCleaner)
JobsFactory.factory().insert('User Service Info Cleaner', UserServiceInfoItemsCleaner)
JobsFactory.factory().insert('User Service Cleaner', UserServiceRemover)
JobsFactory.factory().insert('Deployed Service Info Cleaner', DeployedServiceInfoItemsCleaner)
JobsFactory.factory().insert('Deployed Service Cleaner', DeployedServiceRemover)

View File

@ -524,6 +524,9 @@ class Authenticator(models.Model):
from uds.core import auths
return auths.factory().lookup(self.data_type)
def isOfType(self, type_):
return self.data_type == type_
def getOrCreateUser(self, username, realName = None):
'''
Used to get or create a new user at database associated with this authenticator.