Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect config changes on the fly #3588

Closed
Dracon23 opened this issue Aug 11, 2016 · 12 comments
Closed

Detect config changes on the fly #3588

Dracon23 opened this issue Aug 11, 2016 · 12 comments

Comments

@Dracon23
Copy link

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?

@fari-99
Copy link

fari-99 commented Aug 11, 2016

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.

@Dracon23
Copy link
Author

Dracon23 commented Aug 11, 2016

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

@fari-99
Copy link

fari-99 commented Aug 11, 2016

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.

@Dracon23
Copy link
Author

@fari-99 exactly my thought.

@HecticSeptic
Copy link

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.

@Dracon23
Copy link
Author

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
Copy link
Author

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

@raxxon
Copy link

raxxon commented Aug 12, 2016

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.

@Dracon23
Copy link
Author

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...

@k4n30 k4n30 changed the title [Feature Request] Detect config changes and reload without restarting Detect config changes on the fly Aug 18, 2016
@sohje
Copy link
Contributor

sohje commented Aug 19, 2016

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.

@k4n30
Copy link
Contributor

k4n30 commented Aug 20, 2016

@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

@mjmadsen
Copy link
Contributor

Merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants