Place the persistent task in a task handler
This commit is contained in:
parent
e0eb490814
commit
37c9d65a9d
3 changed files with 72 additions and 69 deletions
|
|
@ -919,7 +919,7 @@ def uses_database(name="sqlite3"):
|
|||
return engine == "django.db.backends.%s" % name
|
||||
|
||||
|
||||
_PERSISTENT_TASKS = None
|
||||
_TASK_HANDLER = None
|
||||
|
||||
def delay(timedelay, callback, *args, **kwargs):
|
||||
"""
|
||||
|
|
@ -931,9 +931,9 @@ def delay(timedelay, callback, *args, **kwargs):
|
|||
arguments after `timedelay` seconds.
|
||||
args (any, optional): Will be used as arguments to callback
|
||||
Kwargs:
|
||||
persistent (bool, optional): should make the delay persistent
|
||||
over a reboot or reload
|
||||
any (any): Will be used to call the callback.
|
||||
persistent (bool, optional): should make the delay persistent
|
||||
over a reboot or reload
|
||||
any (any): Will be used to call the callback.
|
||||
|
||||
Returns:
|
||||
deferred (deferred): Will fire fire with callback after
|
||||
|
|
@ -943,6 +943,8 @@ def delay(timedelay, callback, *args, **kwargs):
|
|||
specified here.
|
||||
|
||||
Note:
|
||||
The task handler (`evennia.scripts.taskhandler.TASK_HANDLEr`) will
|
||||
be called for persistent or non-persistent tasks.
|
||||
If persistent is set to True, the callback, its arguments
|
||||
and other keyword arguments will be saved in the database,
|
||||
assuming they can be. The callback will be executed even after
|
||||
|
|
@ -950,19 +952,11 @@ def delay(timedelay, callback, *args, **kwargs):
|
|||
(and server down time).
|
||||
|
||||
"""
|
||||
global _PERSISTENT_TASKS
|
||||
persistent = kwargs.get("persistent", False)
|
||||
if persistent:
|
||||
del kwargs["persistent"]
|
||||
# Do some imports here to avoid circular import and speed things up
|
||||
if _PERSISTENT_TASKS is None:
|
||||
from evennia.utils.persistent import PERSISTENT_TASKS as _PERSISTENT_TASKS
|
||||
task_id = _PERSISTENT_TASKS.add(timedelay, callback, *args, **kwargs)
|
||||
callback = _PERSISTENT_TASKS.do_task
|
||||
args = [task_id]
|
||||
kwargs = {}
|
||||
|
||||
return task.deferLater(reactor, timedelay, callback, *args, **kwargs)
|
||||
global _TASK_HANDLER
|
||||
# Do some imports here to avoid circular import and speed things up
|
||||
if _TASK_HANDLER is None:
|
||||
from evennia.scripts.taskhandler import TASK_HANDLER as _TASK_HANDLER
|
||||
return _TASK_HANDLER.add(timedelay, callback, *args, **kwargs)
|
||||
|
||||
|
||||
_TYPECLASSMODELS = None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue