Merge branch 'persistent_delay' of git://github.com/vlegoff/evennia into vlegoff-persistent_delay

This commit is contained in:
Griatch 2017-08-10 22:42:31 +02:00
commit 19bb66665b
3 changed files with 212 additions and 3 deletions

View file

@ -44,7 +44,6 @@ _DA = object.__delattr__
_DEFAULT_WIDTH = settings.CLIENT_DEFAULT_WIDTH
def is_iter(iterable):
"""
Checks if an object behaves iterably.
@ -920,6 +919,8 @@ def uses_database(name="sqlite3"):
return engine == "django.db.backends.%s" % name
_TASK_HANDLER = None
def delay(timedelay, callback, *args, **kwargs):
"""
Delay the return of a value.
@ -930,7 +931,9 @@ def delay(timedelay, callback, *args, **kwargs):
arguments after `timedelay` seconds.
args (any, optional): Will be used as arguments to callback
Kwargs:
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
@ -939,8 +942,21 @@ def delay(timedelay, callback, *args, **kwargs):
defined directly in the command body and don't need to be
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
a server restart/reload, taking into account the specified delay
(and server down time).
"""
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