Esempio n. 1
0
def standard_world_update(world, *options):
    nextUpdate = next_tibiacom_whoisonline_update()
    options = list(options)
    while True:
        if "immediate" not in options:
            logging.info("Waiting for %s", time.asctime(time.localtime(nextUpdate)))
            while True:
                if time.time() >= nextUpdate:
                    break
                else:
                    time.sleep(1)
            nextUpdate = next_tibiacom_whoisonline_update()
        else:
            options.remove("immediate")
        startTime = int(time.time())
        update_world_online(world)
        update_recent_deaths(world)
        logging.info("Update took %ds", int(time.time()) - startTime)
        if "once" in options:
            break
Esempio n. 2
0
def standard_world_update(world, *options):
    nextUpdate = next_tibiacom_whoisonline_update()
    options = list(options)
    while True:
        if "immediate" not in options:
            logging.info("Waiting for %s",
                         time.asctime(time.localtime(nextUpdate)))
            while True:
                if time.time() >= nextUpdate:
                    break
                else:
                    time.sleep(1)
            nextUpdate = next_tibiacom_whoisonline_update()
        else:
            options.remove("immediate")
        startTime = int(time.time())
        update_world_online(world)
        update_recent_deaths(world)
        logging.info("Update took %ds", int(time.time()) - startTime)
        if "once" in options:
            break
Esempio n. 3
0
def continuous_update(*worlds):

    worlds = set(worlds)

    def get_option(optstr):
        try:
            worlds.remove(optstr)
            return True
        except KeyError:
            return False

    immediate = get_option("immediate")
    once = get_option("once")
    if not worlds:
        worlds = set((x["name"] for x in dbiface.get_worlds()))

    jobqueue = Queue.Queue()
    threads = []
    errflag = threading.Event()
    for a in xrange(5):
        threads.append(
            threading.Thread(target=_continuous_update_thread_func,
                             args=(jobqueue, errflag)))
        threads[-1].start()

    try:
        nextUpdate = next_tibiacom_whoisonline_update()
        while True:
            if not immediate:
                logging.info("Waiting for %s",
                             time.asctime(time.localtime(nextUpdate)))
                while True:
                    if time.time() >= nextUpdate:
                        break
                    else:
                        time.sleep(int(time.time()) + 1 - time.time())
                nextUpdate = next_tibiacom_whoisonline_update()

            startTime = int(time.time())

            # update the world online lists
            for w in worlds:
                jobqueue.put((TibstatDatabase.update_world_online, w))
            jobqueue.join()
            if errflag.is_set():
                return

            # check the time hasn't gone over into the next update period
            if not immediate:
                assert time.time() < nextUpdate

            charCount = 0
            for w in worlds:
                for row in TibstatDatabase().get_online_chars(
                        after=(nextUpdate - 10 * 60), world=w):
                    jobqueue.put((TibstatDatabase.update_char, row["name"]))
                    charCount += 1
            logging.info("Updating %d chars", charCount)
            jobqueue.join()
            if errflag.is_set():
                return

            logging.info("Update took %ds", int(time.time()) - startTime)
            if once:
                break
            immediate = False
    finally:
        assert jobqueue.empty()
        for a in threads:
            jobqueue.put(None)
        for a in threads:
            a.join()
Esempio n. 4
0
def continuous_update(*worlds):

    worlds = set(worlds)
    def get_option(optstr):
        try:
            worlds.remove(optstr)
            return True
        except KeyError:
            return False
    immediate = get_option("immediate")
    once = get_option("once")
    if not worlds:
        worlds = set((x["name"] for x in dbiface.get_worlds()))

    jobqueue = Queue.Queue()
    threads = []
    errflag = threading.Event()
    for a in xrange(5):
        threads.append(threading.Thread(
                target=_continuous_update_thread_func,
                args=(jobqueue, errflag)))
        threads[-1].start()

    try:
        nextUpdate = next_tibiacom_whoisonline_update()
        while True:
            if not immediate:
                logging.info("Waiting for %s", time.asctime(time.localtime(nextUpdate)))
                while True:
                    if time.time() >= nextUpdate:
                        break
                    else:
                        time.sleep(int(time.time()) + 1 - time.time())
                nextUpdate = next_tibiacom_whoisonline_update()

            startTime = int(time.time())

            # update the world online lists
            for w in worlds:
                jobqueue.put((TibstatDatabase.update_world_online, w))
            jobqueue.join()
            if errflag.is_set():
                return

            # check the time hasn't gone over into the next update period
            if not immediate:
                assert time.time() < nextUpdate

            charCount = 0
            for w in worlds:
                for row in TibstatDatabase().get_online_chars(
                        after=(nextUpdate - 10 * 60),
                        world=w):
                    jobqueue.put((TibstatDatabase.update_char, row["name"]))
                    charCount += 1
            logging.info("Updating %d chars", charCount)
            jobqueue.join()
            if errflag.is_set():
                return

            logging.info("Update took %ds", int(time.time()) - startTime)
            if once:
                break
            immediate = False
    finally:
        assert jobqueue.empty()
        for a in threads:
            jobqueue.put(None)
        for a in threads:
            a.join()