updating delayed task

This commit is contained in:
Adolfo Gómez García 2022-10-21 00:56:12 +02:00
parent a76989d885
commit 13336b966e
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
@ -43,11 +44,11 @@ class DelayedTask(Environmentable):
This is an object that represents an execution to be done "later"
"""
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

@ -139,6 +139,7 @@ class DelayedTaskRunner:
if taskInstance:
logger.debug('Executing delayedTask:>%s<', task)
# Re-create environment data
taskInstance.env = Environment.getEnvForType(taskInstance.__class__)
DelayedTaskThread(taskInstance).start()
@ -146,7 +147,13 @@ class DelayedTaskRunner:
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(