Пример #1
0
    def load(self):
        """Load from the ServerConfig.

        Note:
            This should be automatically called when Evennia starts.
            It populates `self.tasks` according to the ServerConfig.

        """
        to_save = False
        value = ServerConfig.objects.conf("delayed_tasks", default={})
        if isinstance(value, basestring):
            tasks = dbunserialize(value)
        else:
            tasks = value

        # At this point, `tasks` contains a dictionary of still-serialized tasks
        for task_id, value in tasks.items():
            date, callback, args, kwargs = dbunserialize(value)
            if isinstance(callback, tuple):
                # `callback` can be an object and name for instance methods
                obj, method = callback
                if obj is None:
                    to_save = True
                    continue

                callback = getattr(obj, method)
            self.tasks[task_id] = (date, callback, args, kwargs)

        if to_save:
            self.save()
Пример #2
0
    def load(self):
        """Load from the ServerConfig.

        Note:
            This should be automatically called when Evennia starts.
            It populates `self.tasks` according to the ServerConfig.

        """
        to_save = False
        value = ServerConfig.objects.conf("delayed_tasks", default={})
        if isinstance(value, str):
            tasks = dbunserialize(value)
        else:
            tasks = value

        # At this point, `tasks` contains a dictionary of still-serialized tasks
        for task_id, value in tasks.items():
            date, callback, args, kwargs = dbunserialize(value)
            if isinstance(callback, tuple):
                # `callback` can be an object and name for instance methods
                obj, method = callback
                if obj is None:
                    to_save = True
                    continue

                callback = getattr(obj, method)
            self.tasks[task_id] = (date, callback, args, kwargs)

        if to_save:
            self.save()
Пример #3
0
    def restore(self):
        """
        Called when the handler recovers after a Server reload. Called
        by the Server process as part of the reload upstart. Here we
        overload the tickerhandler's restore method completely to make
        sure we correctly re-apply and re-initialize the correct
        monitor and repeater objecth on all saved objects.

        """
        # load the oob monitors and initialize them
        oob_storage = ServerConfig.objects.conf(key=self.oob_save_name)
        if oob_storage:
            self.oob_storage = dbunserialize(oob_storage)
            for store_key, (args, kwargs) in self.oob_storage.items():
                # re-create the monitors
                obj, sessid, fieldname, oobfuncname = store_key
                obj = unpack_dbobj(obj)
                self._add_monitor(obj, sessid, fieldname, oobfuncname, *args, **kwargs)
        # handle the tickers (same as in TickerHandler except we  call
        # the add_repeater method which makes sure to add the hooks before
        # starting the tickerpool)
        ticker_storage = ServerConfig.objects.conf(key=self.save_name)
        if ticker_storage:
            self.ticker_storage = dbunserialize(ticker_storage)
            for store_key, (args, kwargs) in self.ticker_storage.items():
                obj, interval, idstring = store_key
                obj = unpack_dbobj(obj)
                # we saved these in add_repeater before, can now retrieve them
                sessid = kwargs["_sessid"]
                oobfuncname = kwargs["_oobfuncname"]
                self.add_repeater(obj, sessid, oobfuncname, interval, *args, **kwargs)
Пример #4
0
 def restore(self):
     """
     Called when the handler recovers after a Server reload. Called
     by the Server process as part of the reload upstart. Here we
     overload the tickerhandler's restore method completely to make
     sure we correctly re-apply and re-initialize the correct
     monitor and repeater objecth on all saved objects.
     """
     # load the oob monitors and initialize them
     oob_storage = ServerConfig.objects.conf(key=self.oob_save_name)
     if oob_storage:
         self.oob_storage = dbunserialize(oob_storage)
         for store_key, (args, kwargs) in self.oob_storage.items():
             # re-create the monitors
             obj, sessid, fieldname, oobfuncname = store_key
             obj = unpack_dbobj(obj)
             self._add_monitor(obj, sessid, fieldname, oobfuncname, *args, **kwargs)
     # handle the tickers (same as in TickerHandler except we  call
     # the add_repeater method which makes sure to add the hooks before
     # starting the tickerpool)
     ticker_storage = ServerConfig.objects.conf(key=self.save_name)
     if ticker_storage:
         self.ticker_storage = dbunserialize(ticker_storage)
         for store_key, (args, kwargs) in self.ticker_storage.items():
             obj, interval, idstring = store_key
             obj = unpack_dbobj(obj)
             # we saved these in add_repeater before, can now retrieve them
             sessid = kwargs["_sessid"]
             oobfuncname = kwargs["_oobfuncname"]
             self.add_repeater(obj, sessid, oobfuncname, interval, *args, **kwargs)
Пример #5
0
    def restore(self, server_reload=True):
        """
        Restore our monitors after a reload. This is called
        by the server process.

        Args:
            server_reload (bool, optional): If this is False, it means
                the server went through a cold reboot and all
                non-persistent tickers must be killed.

        """
        self.monitors = defaultdict(lambda: defaultdict(dict))
        restored_monitors = ServerConfig.objects.conf(key=self.savekey)
        if restored_monitors:
            restored_monitors = dbunserialize(restored_monitors)
            for (obj, fieldname, idstring, path, persistent, kwargs) in restored_monitors:
                try:
                    if not persistent and not server_reload:
                        # this monitor will not be restarted
                        continue
                    modname, varname = path.rsplit(".", 1)
                    callback = variable_from_module(modname, varname)
                    if obj and hasattr(obj, fieldname):
                        self.monitors[obj][fieldname][idstring] = (callback, persistent, kwargs)
                except Exception:
                    continue
        # make sure to clean data from database
        ServerConfig.objects.conf(key=self.savekey, delete=True)
Пример #6
0
    def restore(self, server_reload=True):
        """
        Restore our monitors after a reload. This is called
        by the server process.

        Args:
            server_reload (bool, optional): If this is False, it means
                the server went through a cold reboot and all
                non-persistent tickers must be killed.

        """
        self.monitors = defaultdict(lambda: defaultdict(dict))
        restored_monitors = ServerConfig.objects.conf(key=self.savekey)
        if restored_monitors:
            restored_monitors = dbunserialize(restored_monitors)
            for (obj, fieldname, idstring, path, persistent,
                 kwargs) in restored_monitors:
                try:
                    if not persistent and not server_reload:
                        # this monitor will not be restarted
                        continue
                    modname, varname = path.rsplit(".", 1)
                    callback = variable_from_module(modname, varname)
                    if obj and hasattr(obj, fieldname):
                        self.monitors[obj][fieldname][idstring] = (callback,
                                                                   persistent,
                                                                   kwargs)
                except Exception:
                    continue
        # make sure to clean data from database
        ServerConfig.objects.conf(key=self.savekey, delete=True)
Пример #7
0
    def restore(self, server_reload=True):
        """
        Restore ticker_storage from database and re-initialize the
        handler from storage. This is triggered by the server at
        restart.

        Args:
            server_reload (bool, optional): If this is False, it means
                the server went through a cold reboot and all
                non-persistent tickers must be killed.

        """
        # load stored command instructions and use them to re-initialize handler
        restored_tickers = ServerConfig.objects.conf(key=self.save_name)
        if restored_tickers:
            # the dbunserialize will convert all serialized dbobjs to real objects

            restored_tickers = dbunserialize(restored_tickers)
            self.ticker_storage = {}
            for store_key, (args, kwargs) in restored_tickers.iteritems():
                try:
                    # at this point obj is the actual object (or None) due to how
                    # the dbunserialize works
                    obj, callfunc, path, interval, idstring, persistent = store_key
                    if not persistent and not server_reload:
                        # this ticker will not be restarted
                        continue
                    if isinstance(callfunc, basestring) and not obj:
                        # methods must have an existing object
                        continue
                    # we must rebuild the store_key here since obj must not be
                    # stored as the object itself for the store_key to be hashable.
                    store_key = self._store_key(obj, path, interval, callfunc,
                                                idstring, persistent)

                    if obj and callfunc:
                        kwargs["_callback"] = callfunc
                        kwargs["_obj"] = obj
                    elif path:
                        modname, varname = path.rsplit(".", 1)
                        callback = variable_from_module(modname, varname)
                        kwargs["_callback"] = callback
                        kwargs["_obj"] = None
                    else:
                        # Neither object nor path - discard this ticker
                        log_err(
                            "Tickerhandler: Removing malformed ticker: %s" %
                            str(store_key))
                        continue
                except Exception:
                    # this suggests a malformed save or missing objects
                    log_trace("Tickerhandler: Removing malformed ticker: %s" %
                              str(store_key))
                    continue
                # if we get here we should create a new ticker
                self.ticker_storage[store_key] = (args, kwargs)
                self.ticker_pool.add(store_key, *args, **kwargs)
Пример #8
0
    def restore(self, server_reload=True):
        """
        Restore ticker_storage from database and re-initialize the
        handler from storage. This is triggered by the server at
        restart.

        Args:
            server_reload (bool, optional): If this is False, it means
                the server went through a cold reboot and all
                non-persistent tickers must be killed.

        """
        # load stored command instructions and use them to re-initialize handler
        restored_tickers = ServerConfig.objects.conf(key=self.save_name)
        if restored_tickers:
            # the dbunserialize will convert all serialized dbobjs to real objects

            restored_tickers = dbunserialize(restored_tickers)
            self.ticker_storage = {}
            for store_key, (args, kwargs) in restored_tickers.iteritems():
                try:
                    # at this point obj is the actual object (or None) due to how
                    # the dbunserialize works
                    obj, callfunc, path, interval, idstring, persistent = store_key
                    if not persistent and not server_reload:
                        # this ticker will not be restarted
                        continue
                    if isinstance(callfunc, basestring) and not obj:
                        # methods must have an existing object
                        continue
                    # we must rebuild the store_key here since obj must not be
                    # stored as the object itself for the store_key to be hashable.
                    store_key = self._store_key(obj, path, interval, callfunc, idstring, persistent)

                    if obj and callfunc:
                        kwargs["_callback"] = callfunc
                        kwargs["_obj"] = obj
                    elif path:
                        modname, varname = path.rsplit(".", 1)
                        callback = variable_from_module(modname, varname)
                        kwargs["_callback"] = callback
                        kwargs["_obj"] = None
                    else:
                        # Neither object nor path - discard this ticker
                        log_err("Tickerhandler: Removing malformed ticker: %s" % str(store_key))
                        continue
                except Exception:
                    # this suggests a malformed save or missing objects
                    log_trace("Tickerhandler: Removing malformed ticker: %s" % str(store_key))
                    continue
                # if we get here we should create a new ticker
                self.ticker_storage[store_key] = (args, kwargs)
                self.ticker_pool.add(store_key, *args, **kwargs)
Пример #9
0
 def restore(self):
     """
     Restore ticker_storage from database and re-initialize the handler from storage. This is triggered by the server at restart.
     """
     # load stored command instructions and use them to re-initialize handler
     ticker_storage = ServerConfig.objects.conf(key=self.save_name)
     if ticker_storage:
         self.ticker_storage = dbunserialize(ticker_storage)
         #print "restore:", self.ticker_storage
         for store_key, (args, kwargs) in self.ticker_storage.items():
             obj, interval, idstring = store_key
             obj = unpack_dbobj(obj)
             _, store_key = self._store_key(obj, interval, idstring)
             self.ticker_pool.add(store_key, obj, interval, *args, **kwargs)
Пример #10
0
 def restore(self):
     """
     Restore ticker_storage from database and re-initialize the handler from storage. This is triggered by the server at restart.
     """
     # load stored command instructions and use them to re-initialize handler
     ticker_storage = ServerConfig.objects.conf(key=self.save_name)
     if ticker_storage:
         self.ticker_storage = dbunserialize(ticker_storage)
         #print "restore:", self.ticker_storage
         for store_key, (args, kwargs) in self.ticker_storage.items():
             obj, interval, idstring = store_key
             obj = unpack_dbobj(obj)
             _, store_key = self._store_key(obj, interval, idstring)
             self.ticker_pool.add(store_key, obj, interval, *args, **kwargs)
Пример #11
0
    def restore(self, server_reload=True):
        """
        Restore ticker_storage from database and re-initialize the
        handler from storage. This is triggered by the server at
        restart.

        Args:
            server_reload (bool, optional): If this is False, it means
                the server went through a cold reboot and all
                non-persistent tickers must be killed.

        """
        # load stored command instructions and use them to re-initialize handler
        restored_tickers = ServerConfig.objects.conf(key=self.save_name)
        if restored_tickers:
            # the dbunserialize will convert all serialized dbobjs to real objects

            restored_tickers = dbunserialize(restored_tickers)
            ticker_storage = {}
            for store_key, (args, kwargs) in restored_tickers.iteritems():
                try:
                    obj, methodname, path, interval, idstring, persistent = store_key
                    if not persistent and not server_reload:
                        # this ticker will not be restarted
                        continue
                    if obj and methodname:
                        kwargs["_callback"] = methodname
                        kwargs["_obj"] = obj
                    elif path:
                        modname, varname = path.rsplit(".", 1)
                        callback = variable_from_module(modname, varname)
                        kwargs["_callback"] = callback
                        kwargs["_obj"] = None
                    ticker_storage[store_key] = (args, kwargs)
                except Exception as err:
                    # this suggests a malformed save or missing objects
                    log_err(
                        "%s\nTickerhandler: Removing malformed ticker: %s" %
                        (err, str(store_key)))
                    continue
                self.ticker_storage = ticker_storage
                self.ticker_pool.add(store_key, *args, **kwargs)
Пример #12
0
    def restore(self, server_reload=True):
        """
        Restore ticker_storage from database and re-initialize the
        handler from storage. This is triggered by the server at
        restart.

        Args:
            server_reload (bool, optional): If this is False, it means
                the server went through a cold reboot and all
                non-persistent tickers must be killed.

        """
        # load stored command instructions and use them to re-initialize handler
        restored_tickers = ServerConfig.objects.conf(key=self.save_name)
        if restored_tickers:
            # the dbunserialize will convert all serialized dbobjs to real objects

            restored_tickers = dbunserialize(restored_tickers)
            ticker_storage = {}
            for store_key, (args, kwargs) in restored_tickers.iteritems():
                try:
                    obj, methodname, path, interval, idstring, persistent = store_key
                    if not persistent and not server_reload:
                        # this ticker will not be restarted
                        continue
                    if obj and methodname:
                        kwargs["_callback"] = methodname
                        kwargs["_obj"] = obj
                    elif path:
                        modname, varname = path.rsplit(".", 1)
                        callback = variable_from_module(modname, varname)
                        kwargs["_callback"] = callback
                        kwargs["_obj"] = None
                    ticker_storage[store_key] = (args, kwargs)
                except Exception as err:
                    # this suggests a malformed save or missing objects
                    log_err("%s\nTickerhandler: Removing malformed ticker: %s" % (err, str(store_key)))
                    continue
                self.ticker_storage = ticker_storage
                self.ticker_pool.add(store_key, *args, **kwargs)