flower
flower copied to clipboard
Persistence not working with docker compose ?
Hi, Here is my docker-compose conf using flower + celery + flask. Do I have to use a db container too ?
version: "3.8"
services:
flask:
build: .
volumes:
- ./src:/src
- ./workspace:/workspace
ports:
- "80:5000"
env_file: .env
command: XXX
redis:
image: "redis:alpine"
celery:
build: .
command: celery -A app.celery worker --concurrency=1 -l INFO --beat -l INFO
volumes:
- ./src:/src
- ./workspace:/workspace
env_file: .env
depends_on:
- flask
- redis
flower:
image: mher/flower
restart: always
command: celery flower --persistent=True
environment:
- CELERY_BROKER_URL=redis://redis:6379/0
- FLOWER_PORT=8888
ports:
- 8888:8888
depends_on:
- redis
- celery
Each time I do an up and down or just a restart of flower container, all datas are removed.
I've got more information. I found some limitations here : https://github.com/mher/flower/issues/662
But it doesn't solve the dashboard problem.
If I look in the task page, I can see Showing 1 to 10 of 10,042 entries
at the bottom
But in the dashboard I see Active: 0 Processed: 42 Failed: 0 Succeeded: 42 Retried: 0
So the docker restart cleans the dashboard statistics.
When you are recreating the containers you are also recreating the file system that Flower saves the object persistence db to. Flower will persist if the process is restarted on the same file system, but obviously won't persist if a container file system gets recreated, thereby wiping it. You'll need to mount or store the persistence object outside of the container file system if you want it to persist across container restarts.
Hi @ENG-Jole , I've used persistance and volume (in the second message), I added like this :
flower:
image: mher/flower
restart: always
command: celery flower --persistent=True
environment:
- CELERY_BROKER_URL=redis://redis:6379/0
- FLOWER_PORT=8888
ports:
- 8888:8888
depends_on:
- redis
- celery
volumes:
- flower_data:/data
volumes:
flower_data:
I can see all process in the tasks page, but not in the dashboard after restart. (Maybe I missed something in your comment)
I'm not sure where you're getting flower_data or data from. Flower will just save the state to a flower.db file at its working directory; there's no specific directory other than that. You'll need to mount the directory the command is running from rather than data.
I think it would be a good idea however to be able to specify the persistence directory. I'll open an enhancement for this.
I'm struggling with this one too. I manage to save some information, but it is not consistent across tabs e.g.:
the dashboard misses information that is available on the tasks tab
I also seem to have this problem running flower on Kubernetes.
My guess is that when restarting it also restarts the worker and the dashboard is counting the results from the new celery worker.
I see in flower docs that we can enable persistence at Flower end. However, there seems to be more than one variable that needs to be configured to get this working. I understood this by experimenting at my end against the docs. I think, the docs can be improved to indicate these variables' dependencies with respect to the Flower's persistence.
The following config (docker-compose.yml snippet) of flower works for me to store the data at flower end and retain the data even after service restarts. After this, the flower dashboard has shown me the historical tasks even after restart (docker-compose down followed by docker-compose up).
flower:
image: mher/flower
container_name: flower
environment:
- CELERY_BROKER_URL=redis://redis:6379/0
- FLOWER_PORT=5555
- FLOWER_PERSISTENT=True
- FLOWER_STATE_SAVE_INTERVAL=10000
- FLOWER_DB=/etc/db/flower.db
ports:
- "5555:5555"
volumes:
- ./flower/storage:/etc/db/
depends_on:
- redis
Note, as we restart the containers, docker will assign new container ids and hence new worked node id for the celery workers. This will lead to difference in the information shown in different tabs. For instance, the Tasks screen might show the historical tasks list processed by a old containers (offline workers or obsolete workers in this case) and tasks with new container id (if new tasks are carried out in Celery). However the Dashboard shows only the summarized result pertaining to the new containers (online celery workers) and does not show the past summarized stats for those old containers. Also, when you click on the old workers related links from Task tab, you won't get any details shown.
All the above are based on my interpretation when using the latest image of Flower tool (as of this comment post date).
I'm seeing the same thing as @rajkumarvenkatasamy . Thank you for the detailed write-up. With the env vars that they used, I am able to confirm that the data is being retained across container restarts. However, the main status page shows reset statistics. You have to click through to the "active" , "processed", or "failed" tabs to see the previous tasks.