mirror of
https://github.com/evennia/evennia.git
synced 2026-03-29 12:07:17 +02:00
Add maintenace task to portal, dropping db connection to resolve mysql timeouts. Resolves #2101.
This commit is contained in:
parent
9de21ca51b
commit
9c0083d272
1 changed files with 24 additions and 1 deletions
|
|
@ -13,6 +13,7 @@ import time
|
|||
|
||||
from os.path import dirname, abspath
|
||||
from twisted.application import internet, service
|
||||
from twisted.internet.task import LoopingCall
|
||||
from twisted.internet import protocol, reactor
|
||||
from twisted.python.log import ILogObserver
|
||||
|
||||
|
|
@ -20,6 +21,7 @@ import django
|
|||
|
||||
django.setup()
|
||||
from django.conf import settings
|
||||
from django.db import connection
|
||||
|
||||
import evennia
|
||||
|
||||
|
|
@ -101,10 +103,29 @@ except ImportError:
|
|||
WEB_PLUGINS_MODULE = None
|
||||
INFO_DICT["errors"] = (
|
||||
"WARNING: settings.WEB_PLUGINS_MODULE not found - "
|
||||
"copy 'evennia/game_template/server/conf/web_plugins.py to mygame/server/conf."
|
||||
"copy 'evennia/game_template/server/conf/web_plugins.py to "
|
||||
"mygame/server/conf."
|
||||
)
|
||||
|
||||
|
||||
_MAINTENANCE_COUNT = 0
|
||||
|
||||
|
||||
def _portal_maintenance():
|
||||
"""
|
||||
Repeated maintenance tasks for the portal.
|
||||
|
||||
"""
|
||||
global _MAINTENANCE_COUNT
|
||||
|
||||
_MAINTENANCE_COUNT += 1
|
||||
|
||||
if _MAINTENANCE_COUNT % (3600 * 7) == 0:
|
||||
# drop database connection every 7 hrs to avoid default timeouts on MySQL
|
||||
# (see https://github.com/evennia/evennia/issues/1376)
|
||||
connection.close()
|
||||
|
||||
|
||||
# -------------------------------------------------------------
|
||||
# Portal Service object
|
||||
# -------------------------------------------------------------
|
||||
|
|
@ -142,6 +163,8 @@ class Portal(object):
|
|||
self.server_info_dict = {}
|
||||
|
||||
self.start_time = time.time()
|
||||
self.maintenance_task = LoopingCall(_portal_maintenance)
|
||||
self.maintenance_task.start(60, now=True) # call every minute
|
||||
|
||||
# in non-interactive portal mode, this gets overwritten by
|
||||
# cmdline sent by the evennia launcher
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue