Flush Flower database occasionally and/or exit gracefully from Docker?

家住魔仙堡 提交于 2019-12-11 13:55:49

问题


I'm running Celery Flower in Docker (see this question for details). The command ends up being:

celery -A proj flower --persistent=True --db=/flower/flower

I've got a persistent volume all set up on /flower. However, it looks like Flower never writes anything to its database file, even after 30 minutes of uptime (during which ~120 tasks were processed):

-rw-r--r--  1 user user    0 Mar 11 00:08 flower.bak
-rw-r--r--  1 user user    0 Mar 10 23:29 flower.dat
-rw-r--r--  1 user user    0 Mar 11 00:08 flower.dir

Stopping the Docker container gracefully doesn't work, and so Docker forcefully kills it, which means nothing ends up being written to the database and so it's as if nothing was persisted.

Is there a way to get Flower to either flush its database occasionally, or, better yet, to exit gracefully?


回答1:


To flush out, you can set max_tasks to a suitable number.

celery -A proj flower --persistent=True --db=/flower/flower --max_tasks=100

This limits number of tasks that will be stored in the db. Once limit is reached, it will discard old tasks.

You can checkout docs for more configuration options.




回答2:


There is no detail in the Flower document, but after checking the code, I found the only place it writes back to the db file is when Flower is stopped gracefully. This is the latest code (v0.9.2)1:

def stop(self):
    if self.persistent:
        logger.debug("Saving state to '%s'...", self.db)
        state = shelve.open(self.db)
        state['events'] = self.state
        state.close()

This means you can do nothing on the Flower side, yet, unless you want to change the code.

However, on the Docker side, you may ensure that it graceful shutdown the container with docker container stop, so Flower's stop() function is invoked properly. To achieve this, you need to make sure your container command is using "exec form" over "shell form"2, as recommended in the document.

I also found a discussion over a similar problem with another service. Have a look there if you need more detailed explanation3.


Reference:

  1. Flower code on Github
  2. DockerFile CMD document
  3. Discussion of a similar issue with SQL Server Docker on Github


来源:https://stackoverflow.com/questions/35929907/flush-flower-database-occasionally-and-or-exit-gracefully-from-docker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!