Make TaskHandler properly handle missing attribute on server reload. Resolve #3620

This commit is contained in:
Griatch 2024-09-29 12:57:19 +02:00
parent 2b95446dd0
commit c476121a6c
2 changed files with 12 additions and 5 deletions

View file

@ -36,6 +36,8 @@ did not add it to the handler's object (Griatch)
respected (Griatch)
- [Fix][issue3624]: Setting tags with integer names caused errors on postgres (Griatch)
- [Fix][issue3615]: Using `print()` in `py` caused an infinite loop (Griatch)
- [Fix][issue3620]: Better handle TaskHandler running against an attribute that
was removed since last reload (Griatch)
- [Docs][issue3591]: Fix of NPC reaction tutorial code (Griatch)
- Docs: Tutorial fixes (Griatch, aMiss-aWry, feyrkh)
@ -46,6 +48,7 @@ did not add it to the handler's object (Griatch)
[issue3612]: https://github.com/evennia/evennia/issues/3612
[issue3624]: https://github.com/evennia/evennia/issues/3624
[issue3615]: https://github.com/evennia/evennia/issues/3615
[issue3620]: https://github.com/evennia/evennia/issues/3620
[pull3595]: https://github.com/evennia/evennia/pull/3595
[pull3533]: https://github.com/evennia/evennia/pull/3533
[pull3594]: https://github.com/evennia/evennia/pull/3594

View file

@ -5,13 +5,12 @@ Module containing the task handler for Evennia deferred tasks, persistent or not
from datetime import datetime, timedelta
from pickle import PickleError
from twisted.internet import reactor
from twisted.internet.defer import CancelledError as DefCancelledError
from twisted.internet.task import deferLater
from evennia.server.models import ServerConfig
from evennia.utils.dbserialize import dbserialize, dbunserialize
from evennia.utils.logger import log_err
from twisted.internet import reactor
from twisted.internet.defer import CancelledError as DefCancelledError
from twisted.internet.task import deferLater
TASK_HANDLER = None
@ -251,7 +250,12 @@ class TaskHandler:
to_save = True
continue
callback = getattr(obj, method)
try:
callback = getattr(obj, method)
except Exception as e:
log_err(f"TaskHandler: Unable to load task {task_id} (disabling it): {e}")
to_save = True
continue
self.tasks[task_id] = (date, callback, args, kwargs, True, None)
if self.stale_timeout > 0: # cleanup stale tasks.