forked from shaba/openuds
updating delayed task
This commit is contained in:
parent
a76989d885
commit
13336b966e
@ -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:
|
||||
"""
|
||||
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user