Run migrations! Removed global system scripts, moving into maintenance functions on the portal and server level. This means that runtimes will be reset as the system resets to the new system.
This commit is contained in:
parent
6dcc1b80b0
commit
895f8504cd
3 changed files with 26 additions and 26 deletions
|
|
@ -604,7 +604,7 @@ class CmdTime(MuxCommand):
|
||||||
table.align = 'l'
|
table.align = 'l'
|
||||||
table.add_row(["Current server uptime", utils.time_format(gametime.uptime(), 3)])
|
table.add_row(["Current server uptime", utils.time_format(gametime.uptime(), 3)])
|
||||||
table.add_row(["Total server running time", utils.time_format(gametime.runtime(), 2)])
|
table.add_row(["Total server running time", utils.time_format(gametime.runtime(), 2)])
|
||||||
table.add_row(["Total in-game time (realtime x %g" % (gametime.TIMEFACTOR), utils.time_format(gametime.gametime(), 2)])
|
table.add_row(["Total in-game time (realtime x %g)" % (gametime.TIMEFACTOR), utils.time_format(gametime.gametime(), 2)])
|
||||||
table.add_row(["Server time stamp", datetime.datetime.now()])
|
table.add_row(["Server time stamp", datetime.datetime.now()])
|
||||||
self.caller.msg(str(table))
|
self.caller.msg(str(table))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,22 +79,31 @@ WEBCLIENT_ENABLED = settings.WEBCLIENT_ENABLED
|
||||||
_MAINTENANCE_COUNT = 0
|
_MAINTENANCE_COUNT = 0
|
||||||
_FLUSH_CACHE = None
|
_FLUSH_CACHE = None
|
||||||
_IDMAPPER_CACHE_MAXSIZE = settings.IDMAPPER_CACHE_MAXSIZE
|
_IDMAPPER_CACHE_MAXSIZE = settings.IDMAPPER_CACHE_MAXSIZE
|
||||||
|
_GAMETIME_MODULE = None
|
||||||
|
|
||||||
def _server_maintenance():
|
def _server_maintenance():
|
||||||
"""
|
"""
|
||||||
This maintenance function handles repeated checks and updates that
|
This maintenance function handles repeated checks and updates that
|
||||||
the server needs to do. It is called every 5 minutes.
|
the server needs to do. It is called every 5 minutes.
|
||||||
"""
|
"""
|
||||||
global EVENNIA, _MAINTENANCE_COUNT
|
global EVENNIA, _MAINTENANCE_COUNT, _FLUSH_CACHE, _GAMETIME_MODULE
|
||||||
global _FLUSH_CACHE
|
|
||||||
if not _FLUSH_CACHE:
|
if not _FLUSH_CACHE:
|
||||||
from evennia.utils.idmapper.models import conditional_flush as _FLUSH_CACHE
|
from evennia.utils.idmapper.models import conditional_flush as _FLUSH_CACHE
|
||||||
|
if not _GAMETIME_MODULE:
|
||||||
|
from evennia.utils import gametime as _GAMETIME_MODULE
|
||||||
|
|
||||||
_MAINTENANCE_COUNT += 1
|
_MAINTENANCE_COUNT += 1
|
||||||
|
|
||||||
# update game time
|
now = time.time()
|
||||||
EVENNIA.runtime += 60.0
|
if _MAINTENANCE_COUNT == 1:
|
||||||
ServerConfig.objects.conf("runtime", EVENNIA.runtime)
|
# first call after a reload
|
||||||
EVENNIA.runtime_last_saved = time.time()
|
_GAMETIME_MODULE.SERVER_START_TIME = now
|
||||||
|
_GAMETIME_MODULE.SERVER_RUNTIME = ServerConfig.objects.conf("runtime", default=0.0)
|
||||||
|
else:
|
||||||
|
_GAMETIME_MODULE.SERVER_RUNTIME += 60.0
|
||||||
|
# update game time and save it across reloads
|
||||||
|
_GAMETIME_MODULE.SERVER_RUNTIME_LAST_UPDATED = now
|
||||||
|
ServerConfig.objects.conf("runtime", _GAMETIME_MODULE.SERVER_RUNTIME)
|
||||||
|
|
||||||
if _MAINTENANCE_COUNT % 300 == 0:
|
if _MAINTENANCE_COUNT % 300 == 0:
|
||||||
# check cache size every 5 minutes
|
# check cache size every 5 minutes
|
||||||
|
|
@ -108,7 +117,8 @@ def _server_maintenance():
|
||||||
# validate channels off-sync with scripts
|
# validate channels off-sync with scripts
|
||||||
print "maintenance: validate channels..."
|
print "maintenance: validate channels..."
|
||||||
evennia.CHANNEL_HANDLER.update()
|
evennia.CHANNEL_HANDLER.update()
|
||||||
|
maintenance_task = LoopingCall(_server_maintenance)
|
||||||
|
maintenance_task.start(60, now=True) # call every minute
|
||||||
|
|
||||||
#------------------------------------------------------------
|
#------------------------------------------------------------
|
||||||
# Evennia Main Server object
|
# Evennia Main Server object
|
||||||
|
|
@ -139,6 +149,8 @@ class Evennia(object):
|
||||||
# Database-specific startup optimizations.
|
# Database-specific startup optimizations.
|
||||||
self.sqlite3_prep()
|
self.sqlite3_prep()
|
||||||
|
|
||||||
|
self.start_time = time.time()
|
||||||
|
|
||||||
# Run the initial setup if needed
|
# Run the initial setup if needed
|
||||||
self.run_initial_setup()
|
self.run_initial_setup()
|
||||||
|
|
||||||
|
|
@ -152,10 +164,6 @@ class Evennia(object):
|
||||||
self.game_running = True
|
self.game_running = True
|
||||||
|
|
||||||
# track the server time
|
# track the server time
|
||||||
self.start_time = time.time()
|
|
||||||
self.runtime = ServerConfig.objects.conf("runtime", default=0.0)
|
|
||||||
self.runtime_last_saved = self.start_time
|
|
||||||
|
|
||||||
self.run_init_hooks()
|
self.run_init_hooks()
|
||||||
|
|
||||||
# Server startup methods
|
# Server startup methods
|
||||||
|
|
@ -525,6 +533,3 @@ if os.name == 'nt':
|
||||||
with open(os.path.join(settings.GAME_DIR, 'server.pid'), 'w') as f:
|
with open(os.path.join(settings.GAME_DIR, 'server.pid'), 'w') as f:
|
||||||
f.write(str(os.getpid()))
|
f.write(str(os.getpid()))
|
||||||
|
|
||||||
# start the maintenance task
|
|
||||||
maintenance_task = LoopingCall(_server_maintenance)
|
|
||||||
maintenance_task.start(60) # call every minute
|
|
||||||
|
|
|
||||||
|
|
@ -31,9 +31,10 @@ WEEK = DAY * settings.TIME_DAY_PER_WEEK
|
||||||
MONTH = WEEK * settings.TIME_WEEK_PER_MONTH
|
MONTH = WEEK * settings.TIME_WEEK_PER_MONTH
|
||||||
YEAR = MONTH * settings.TIME_MONTH_PER_YEAR
|
YEAR = MONTH * settings.TIME_MONTH_PER_YEAR
|
||||||
|
|
||||||
# link to the main Server
|
# these are kept updated by the server maintenance loop
|
||||||
_EVENNIA = None
|
SERVER_START_TIME = 0.0
|
||||||
|
SERVER_RUNTIME_LAST_UPDATED = 0.0
|
||||||
|
SERVER_RUNTIME = 0.0
|
||||||
|
|
||||||
def _format(seconds, *divisors) :
|
def _format(seconds, *divisors) :
|
||||||
"""
|
"""
|
||||||
|
|
@ -65,20 +66,14 @@ def _format(seconds, *divisors) :
|
||||||
|
|
||||||
def runtime(format=False):
|
def runtime(format=False):
|
||||||
"Get the total runtime of the server since first start (minus downtimes)"
|
"Get the total runtime of the server since first start (minus downtimes)"
|
||||||
global _EVENNIA
|
runtime = SERVER_RUNTIME + (time() - SERVER_RUNTIME_LAST_UPDATED)
|
||||||
if not _EVENNIA:
|
|
||||||
from evennia.server.server import EVENNIA as _EVENNIA
|
|
||||||
runtime = _EVENNIA.runtime + (time() - _EVENNIA.runtime_last_saved)
|
|
||||||
if format:
|
if format:
|
||||||
return _format(runtime, 31536000, 2628000, 604800, 86400, 3600, 60)
|
return _format(runtime, 31536000, 2628000, 604800, 86400, 3600, 60)
|
||||||
return runtime
|
return runtime
|
||||||
|
|
||||||
def uptime(format=False):
|
def uptime(format=False):
|
||||||
"Get the current uptime of the server since last reload"
|
"Get the current uptime of the server since last reload"
|
||||||
global _EVENNIA
|
uptime = time() - SERVER_START_TIME
|
||||||
if not _EVENNIA:
|
|
||||||
from evennia.server.server import EVENNIA as _EVENNIA
|
|
||||||
uptime = time() - _EVENNIA.start_time
|
|
||||||
if format:
|
if format:
|
||||||
return _format(uptime, 31536000, 2628000, 604800, 86400, 3600, 60)
|
return _format(uptime, 31536000, 2628000, 604800, 86400, 3600, 60)
|
||||||
return uptime
|
return uptime
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue