Fix error in MonitorHandler recovering a saved Session across a reload. This probably affected the TickerHandler as well. Add a new hook to the server object that gets called once the portal has synced, and run the monitorhandler/tickerhandler restores there. Also some changes to the serialization of Sessions. Resolves #1164.

This commit is contained in:
Griatch 2017-01-15 19:55:51 +01:00
parent b46bc9b2aa
commit 052e1845a2
6 changed files with 70 additions and 34 deletions

View file

@ -133,7 +133,7 @@ class ScriptDBManager(TypedObjectManager):
return nr_deleted
def validate(self, scripts=None, obj=None, key=None, dbref=None,
init_mode=False):
init_mode=None):
"""
This will step through the script database and make sure
all objects run scripts that are still valid in the context
@ -153,7 +153,7 @@ class ScriptDBManager(TypedObjectManager):
particular id.
init_mode (str, optional): This is used during server
upstart and can have three values:
- `False` (no init mode). Called during run.
- `None` (no init mode). Called during run.
- `"reset"` - server reboot. Kill non-persistent scripts
- `"reload"` - server reload. Keep non-persistent scripts.
Returns:

View file

@ -71,11 +71,16 @@ class MonitorHandler(object):
restored_monitors = dbunserialize(restored_monitors)
for (obj, fieldname, idstring, path, persistent, kwargs) in restored_monitors:
try:
if not persistent and not server_reload:
if not server_reload and not persistent:
# this monitor will not be restarted
continue
if "session" in kwargs and not kwargs["session"]:
# the session was removed because it no longer
# exists. Don't restart the monitor.
continue
modname, varname = path.rsplit(".", 1)
callback = variable_from_module(modname, varname)
if obj and hasattr(obj, fieldname):
self.monitors[obj][fieldname][idstring] = (callback, persistent, kwargs)
except Exception:
@ -116,6 +121,13 @@ class MonitorHandler(object):
persistent (bool, optional): If False, the monitor will survive
a server reload but not a cold restart. This is default.
Kwargs:
session (Session): If this keyword is given, the monitorhandler will
correctly analyze it and remove the monitor if after a reload/reboot
the session is no longer valid.
any (any): Any other kwargs are passed on to the callback. Remember that
all kwargs must be possible to pickle!
"""
if not fieldname.startswith("db_") or not hasattr(obj, fieldname):
# an Attribute - we track its db_value field