PokemonGo-Bot icon indicating copy to clipboard operation
PokemonGo-Bot copied to clipboard

Detect config changes on the fly

Open Dracon23 opened this issue 10 years ago • 12 comments

New bot user, following development for two weeks now...

I'm still tinkering with the bot, tweaking config here and there... which leads me to my request...

Is it possible to have to bot monitor the config and actually reload it when parts like release, recycling config or tasks to run have changed without having to restart?

Dracon23 avatar Aug 11 '16 09:08 Dracon23

wow, this is a good feature, but if you do that, I will recommend setting the update for every cycle for every like 15 minutes. because if you check it every cycle it will overhead. I think haha. or you can just use keyboard input to check the config. but hey that's a good feature.

fari-99 avatar Aug 11 '16 10:08 fari-99

There are possibilities to do this in python on linux, don't know how mac and windows compare.

Dracon23 avatar Aug 11 '16 10:08 Dracon23

hoo, so you get "notice" the file is changing, and then restart the bot. love to see that happen. if i want to just farming pokeball, i need to delete catch task, after get enough pokebal i put the task back.

fari-99 avatar Aug 11 '16 10:08 fari-99

@fari-99 exactly my thought.

Dracon23 avatar Aug 11 '16 10:08 Dracon23

This is possible on Windows, one of the Po-Go-Map projects had this enabled, though it may have been due to debugging being enabled.

HecticSeptic avatar Aug 11 '16 13:08 HecticSeptic

I haven't touched windows in over two years, let alone did stuff to it (aka wrote something) at all. So I wouldn't know

Just wanted to give some input :F

Dracon23 avatar Aug 11 '16 16:08 Dracon23

Necro does this, so it's def possible on win, just may not be in python

Dracon23 avatar Aug 12 '16 05:08 Dracon23

Just attach it to the relog cycle. Bot already has a login recycle event every 30 minutes or so, just re-read configuration when logging back in.

raxxon avatar Aug 12 '16 09:08 raxxon

I wouldn't want to wait for a relog cycle to be honest... I'm currently investigating a use case for a different app I work on, this shouldn't be too hard from what I gather...

Dracon23 avatar Aug 12 '16 16:08 Dracon23

I already did this with with following changes: Config_changed

def initialize(bot, config):
    tree = TreeConfigBuilder(bot, config.raw_tasks).build()
    bot.workers = tree
    bot.metrics.capture_stats()
    bot.health_record = BotEvent(config)
    bot.config_file = config_file

def check_config_modification(config_file):
    mtime = [os.stat(config_file).st_mtime]
    config_file = config_file

    def check_cfg():
        mdate = os.stat(config_file).st_mtime
        if mtime[0] == mdate:  # mtime didnt change
            return False
        else:
            mtime[0] = mdate
            return True

    return check_cfg

Inside loop, i think there should be a delay beetween checks, but just fast work-around.

while not finished:
    try:
        bot = PokemonGoBot(config)
        bot.start()
        initialize(bot, config)
        config_changed = check_config_modification(config_file)

        bot.event_manager.emit(
            'bot_start', sender=bot,
            level='info', formatted='Starting bot...'
        )

        while True:
            bot.tick()
            if config_changed():
                logger.info('Config changed! Re-apply configuration.')
                config, _ = init_config()
                if config:
                    initialize(bot, config)
                else:
                    logger.info('Check your configration!')

Maybe this will broke some bot logic - im totally new to this project. Not sure about Windows system, but it works under OSx - 10 bots running fine for ~ 7hours.

sohje avatar Aug 19 '16 14:08 sohje

@sohje do you mind creating a pull request? The devs will review it before merging so you can get feedback on if it breaks anything or not

k4n30 avatar Aug 20 '16 05:08 k4n30

Merged

mjmadsen avatar Aug 28 '16 14:08 mjmadsen