mirror of
https://github.com/evennia/evennia.git
synced 2026-03-17 21:36:30 +01:00
Scripts and Exits updated. Fixed some deep issues with Scripts that caused object-based scripts to not properly shut down in some situations, as well as spawn multiple instances of themselves. I think this should resolve all "at_repeat doubling" issues reported. Due to optimizations in the typeclass cache loader in a previous update, the Exit cmdsets were not properly loaded (they were loaded at cache time, which now doesn't happen as often). So Exits instead rely on the new "at_cmdset_get" hook called by the cmdhandler. It allows dynamic modification of cmdsets just before they are accessed. Resolves issue173 (I hope). Resolves issue180. Resolves issue 181.
This commit is contained in:
parent
16affc284b
commit
2b4e008d18
13 changed files with 135 additions and 68 deletions
|
|
@ -88,8 +88,8 @@ class ScriptManager(TypedObjectManager):
|
|||
key = validate only scripts with a particular key
|
||||
dbref = validate only the single script with this particular id.
|
||||
|
||||
init_mode - When this mode is active, non-persistent scripts
|
||||
will be removed and persistent scripts will be
|
||||
init_mode - This is used during server upstart. It causes non-persistent
|
||||
scripts to be removed and persistent scripts to be
|
||||
force-restarted.
|
||||
|
||||
This method also makes sure start any scripts it validates,
|
||||
|
|
@ -117,26 +117,30 @@ class ScriptManager(TypedObjectManager):
|
|||
# This deletes all non-persistent scripts from database
|
||||
nr_stopped += self.remove_non_persistent(obj=obj)
|
||||
# turn off the activity flag for all remaining scripts
|
||||
for script in self.all():
|
||||
script.is_active = False
|
||||
scripts = self.get_all_scripts()
|
||||
for script in scripts:
|
||||
script.dbobj.is_active = False
|
||||
|
||||
elif not scripts:
|
||||
# normal operation
|
||||
if dbref and self.dbref(dbref):
|
||||
scripts = self.get_id(dbref)
|
||||
elif obj:
|
||||
scripts = self.get_all_scripts_on_obj(obj, key=key)
|
||||
else:
|
||||
scripts = self.get_all_scripts(key=key) #self.model.get_all_cached_instances()
|
||||
|
||||
if dbref and self.dbref(dbref):
|
||||
scripts = self.get_id(dbref)
|
||||
elif scripts:
|
||||
pass
|
||||
elif obj:
|
||||
scripts = self.get_all_scripts_on_obj(obj, key=key)
|
||||
else:
|
||||
scripts = self.model.get_all_cached_instances()#get_all_scripts(key=key)
|
||||
if not scripts:
|
||||
# no scripts available to validate
|
||||
VALIDATE_ITERATION -= 1
|
||||
return None, None
|
||||
|
||||
#print "scripts to validate: [%s]" % (", ".join(script.key for script in scripts))
|
||||
for script in scripts:
|
||||
if script.is_valid():
|
||||
#print "validating %s (%i)" % (script.key, id(script.dbobj))
|
||||
#print "validating %s (%i) (init_mode=%s)" % (script.key, id(script.dbobj), init_mode)
|
||||
nr_started += script.start(force_restart=init_mode)
|
||||
#print "back from start."
|
||||
#print "back from start. nr_started=", nr_started
|
||||
else:
|
||||
script.stop()
|
||||
nr_stopped += 1
|
||||
|
|
|
|||
|
|
@ -44,9 +44,10 @@ class ScriptClass(TypeClass):
|
|||
def _stop_task(self):
|
||||
"stop task runner"
|
||||
try:
|
||||
self.ndb.twisted_task.stop()
|
||||
#print "stopping twisted task:", id(self.ndb.twisted_task), self.obj
|
||||
self.ndb.twisted_task.stop()
|
||||
except Exception:
|
||||
pass
|
||||
logger.log_trace()
|
||||
def _step_err_callback(self, e):
|
||||
"callback for runner errors"
|
||||
cname = self.__class__.__name__
|
||||
|
|
@ -74,7 +75,7 @@ class ScriptClass(TypeClass):
|
|||
self.save()
|
||||
def _step_task(self):
|
||||
"step task"
|
||||
try:
|
||||
try:
|
||||
d = maybeDeferred(self._step_succ_callback)
|
||||
d.addErrback(self._step_err_callback)
|
||||
return d
|
||||
|
|
@ -107,30 +108,30 @@ class ScriptClass(TypeClass):
|
|||
"""
|
||||
#print "Script %s (%s) start (active:%s, force:%s) ..." % (self.key, id(self.dbobj),
|
||||
# self.is_active, force_restart)
|
||||
if self.dbobj.db_is_active and not force_restart:
|
||||
# script already runs.
|
||||
|
||||
if self.dbobj.is_active and not force_restart:
|
||||
# script already runs and should not be restarted.
|
||||
return 0
|
||||
|
||||
if self.obj:
|
||||
|
||||
obj = self.obj
|
||||
if obj:
|
||||
# check so the scripted object is valid and initalized
|
||||
try:
|
||||
dummy = object.__getattribute__(self.obj, 'cmdset')
|
||||
dummy = object.__getattribute__(obj, 'cmdset')
|
||||
except AttributeError:
|
||||
# this means the object is not initialized.
|
||||
self.dbobj.db_is_active = False
|
||||
self.dbobj.is_active = False
|
||||
return 0
|
||||
# try to start the script
|
||||
try:
|
||||
self.dbobj.db_is_active = True
|
||||
self.dbobj.save()
|
||||
self.dbobj.is_active = True
|
||||
self.at_start()
|
||||
if self.dbobj.db_interval > 0:
|
||||
self._start_task()
|
||||
return 1
|
||||
except Exception:
|
||||
logger.log_trace()
|
||||
self.dbobj.db_is_active = False
|
||||
self.dbobj.save()
|
||||
self.dbobj.is_active = False
|
||||
return 0
|
||||
|
||||
def stop(self, kill=False):
|
||||
|
|
@ -141,6 +142,8 @@ class ScriptClass(TypeClass):
|
|||
kill - don't call finishing hooks.
|
||||
"""
|
||||
#print "stopping script %s" % self.key
|
||||
#import pdb
|
||||
#pdb.set_trace()
|
||||
if not kill:
|
||||
try:
|
||||
self.at_stop()
|
||||
|
|
@ -149,11 +152,13 @@ class ScriptClass(TypeClass):
|
|||
if self.dbobj.db_interval > 0:
|
||||
try:
|
||||
self._stop_task()
|
||||
except Exception:
|
||||
except Exception, e:
|
||||
logger.log_trace("Stopping script %s(%s)" % (self.key, self.id))
|
||||
pass
|
||||
try:
|
||||
self.dbobj.delete()
|
||||
except AssertionError:
|
||||
logger.log_trace()
|
||||
return 0
|
||||
return 1
|
||||
|
||||
|
|
@ -175,7 +180,7 @@ class ScriptClass(TypeClass):
|
|||
pass
|
||||
|
||||
|
||||
# class ScriptClassOld(TypeClass):
|
||||
# class ScriptClass(TypeClass):
|
||||
# """
|
||||
# Base class for all Scripts.
|
||||
# """
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue