1
0
mirror of https://github.com/dkmstr/openuds.git synced 2025-01-11 05:17:55 +03:00

Merge remote-tracking branch 'origin/v3.6'

This commit is contained in:
Adolfo Gómez García 2022-10-21 00:56:54 +02:00
commit c4fcf7c57e
No known key found for this signature in database
GPG Key ID: DD1ABF20724CDA23
2 changed files with 10 additions and 2 deletions

View File

@ -30,6 +30,7 @@
"""
@author: Adolfo Gómez, dkmaster at dkmon dot com
"""
import typing
import logging
from uds.core.environment import Environmentable, Environment
@ -44,11 +45,11 @@ class DelayedTask(Environmentable):
"""
__slots__ = ()
def __init__(self):
def __init__(self, environment: typing.Optional[Environment] = None) -> None:
"""
Remember to invoke parent init in derived clases using super(myClass,self).__init__() to let this initialize its own variables
"""
super().__init__(Environment('DelayedTask'))
super().__init__(environment or Environment.getEnvForType(self.__class__))
def execute(self) -> None:
"""

View File

@ -137,6 +137,7 @@ class DelayedTaskRunner(metaclass=singleton.Singleton):
if taskInstance:
logger.debug('Executing delayedTask:>%s<', task)
# Re-create environment data
taskInstance.env = Environment.getEnvForType(taskInstance.__class__)
DelayedTaskThread(taskInstance).start()
@ -144,7 +145,13 @@ class DelayedTaskRunner(metaclass=singleton.Singleton):
now = getSqlDatetime()
exec_time = now + timedelta(seconds=delay)
cls = instance.__class__
# Save "env" from delayed task, set it to None and restore it after save
env = instance.env
instance.env = None # type: ignore # clean env before saving pickle, save space (the env will be created again when executing)
instanceDump = codecs.encode(pickle.dumps(instance), 'base64').decode()
instance.env = env
typeName = str(cls.__module__ + '.' + cls.__name__)
logger.debug(