Added a keepalive for the bot to survive IDLE_TIMEOUTs.

This commit is contained in:
Griatch 2014-02-27 01:22:57 +01:00
parent f126d30b36
commit fc89923fa8

View file

@ -4,13 +4,16 @@ Player that are controlled by the server.
""" """
from django.conf import settings
from src.players.player import Player from src.players.player import Player
from src.scripts.scripts import Script from src.scripts.scripts import Script
from src.commands.command import Command from src.commands.command import Command
from src.commands.cmdset import CmdSet from src.commands.cmdset import CmdSet
from src.commands.cmdhandler import CMD_NOMATCH, CMD_LOGINSTART
from src.utils import search from src.utils import search
_IDLE_TIMEOUT = settings.IDLE_TIMEOUT
_IDLE_COMMAND = settings.IDLE_COMMAND
_SESSIONS = None _SESSIONS = None
_CHANNELDB = None _CHANNELDB = None
@ -25,9 +28,13 @@ class BotStarter(Script):
""" """
def at_script_creation(self): def at_script_creation(self):
self.key = "botstarter" self.key = "botstarter"
self.desc = "kickstarts bot" self.desc = "bot start/keepalive"
self.persistent = True self.persistent = True
self.db.started = False self.db.started = False
if _IDLE_TIMEOUT > 0:
# call before idle_timeout triggers
self.interval = int(max(60, _IDLE_TIMEOUT * 0.99))
self.start_delay = True
def at_start(self): def at_start(self):
"Kick bot into gear" "Kick bot into gear"
@ -35,6 +42,10 @@ class BotStarter(Script):
self.player.start() self.player.start()
self.db.started = True self.db.started = True
def at_repeat(self):
"Called self.interval seconds to keep connection."
self.dbobj.execute_cmd(_IDLE_COMMAND)
def at_server_reload(self): def at_server_reload(self):
""" """
If server reloads we don't need to reconnect the protocol If server reloads we don't need to reconnect the protocol