Ejemplo n.º 1
0
def initialize():
    """
    This imports all packages that are descendant of this package, and, after that,
    it register all subclases of service provider as
    """
    import os.path
    import pkgutil
    import sys
    from uds.core import jobs
    from uds.core.managers import taskManager

    # Dinamycally import children of this package.
    pkgpath = os.path.dirname(sys.modules[__name__].__file__)
    for _, name, _ in pkgutil.iter_modules([pkgpath]):
        logger.debug('Importing %s', name)
        __import__(name, globals(), locals(), [], 1)

    p = jobs.Job
    # This is marked as error in IDE, but it's not (__subclasses__)
    for cls in p.__subclasses__():
        logger.debug('Examining worker %s', cls.__module__)
        # Limit to autoregister just workers jobs inside this module
        if cls.__module__[0:16] == 'uds.core.workers':
            logger.debug('Added worker %s to list', cls.__module__)
            taskManager().registerJob(cls)
Ejemplo n.º 2
0
    def handle(self, *args, **options) -> None:
        logger.info("Running task manager command")

        GlobalConfig.initialize()

        start = options.get('start', False)
        stop = options.get('stop', False)
        foreground = options.get('foreground', False)

        logger.debug('Start: %s, Stop: %s, Foreground: %s', start, stop,
                     foreground)

        pid: int = 0
        try:
            pid = int(open(getPidFile(), 'r').readline())
        except Exception:
            pid = 0

        if stop and pid:
            try:
                logger.info('Stopping task manager. pid: %s', pid)
                os.kill(pid, signal.SIGTERM)
                time.sleep(1)  # Wait a bit before running new one
                os.unlink(getPidFile())
            except Exception:
                logger.error(
                    "Could not stop task manager (maybe it's not runing?)")
                os.unlink(getPidFile())

        if start:
            logger.info('Starting task manager.')

            if not foreground:
                become_daemon(settings.BASE_DIR,
                              settings.LOGDIR + '/taskManagerStdout.log',
                              settings.LOGDIR + '/taskManagerStderr.log')
                pid = os.getpid()

                open(getPidFile(), 'w+').write('{}\n'.format(pid))

            manager = taskManager()()
            manager.run()

        if not start and not stop:
            if pid:
                sys.stdout.write(
                    "Task manager found running (pid file exists: {0})\n".
                    format(pid))
            else:
                sys.stdout.write(
                    "Task manager not foud (pid file do not exits)\n")
Ejemplo n.º 3
0
def initialize() -> None:
    """
    This imports all packages that are descendant of this package, and, after that,
    it register all subclases of service provider as
    """
    from uds.core import jobs
    from uds.core.managers import taskManager

    # Dinamycally import children of this package.
    pkgpath = os.path.dirname(sys.modules[__name__].__file__)
    for _, name, _ in pkgutil.iter_modules([pkgpath]):
        logger.debug('Importing worker %s', name)
        # __import__(name, globals(), locals(), [], 1)
        importlib.import_module('.' + name, __name__)  # import module

    importlib.invalidate_caches()

    for cls in jobs.Job.__subclasses__():
        logger.debug('Examining worker %s', cls.__module__)
        # Limit to autoregister just workers jobs inside this module
        if cls.__module__[0:16] == 'uds.core.workers':
            logger.debug('Added worker %s to list', cls.__module__)
            taskManager().registerJob(cls)
Ejemplo n.º 4
0
#
#    * 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.


from .OVirtProvider import Provider
from .OVirtJobs import OVirtHouseKeeping, OVirtDeferredRemoval

from uds.core import managers

# Scheduled task to do clean processes
for cls in (OVirtDeferredRemoval, OVirtHouseKeeping):
    managers.taskManager().registerJob(cls)
Ejemplo n.º 5
0
# 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.

from uds.core import managers

from .provider import OGProvider
from .jobs import OpenGnsysMaintainer

# Scheduled task to do clean processes
for cls in (OpenGnsysMaintainer, ):
    managers.taskManager().registerJob(cls)