flower icon indicating copy to clipboard operation
flower copied to clipboard

Flower show wrong time if timezone set

Open PaleNeutron opened this issue 2 years ago • 5 comments

Describe the bug My local time is UTC+8, but I can not got correct local time in flower view.

My docker settings:

  flower:
    image: mher/flower
    environment:
      - TZ=Asia/Shanghai
      - DEBUG=1
      - CELERY_BROKER=redis://redis:6379/0
      - CELERY_BACKEND=redis://redis:6379/0
      - CELERY_TIMEZONE=Asia/Shanghai
      - CELERY_ENABLE_UTC=True

and the same in worker docker.

task request at local time 21:00 shown 05:00 in flower. it has a 2 * 8 hours different.

at this time, I checked task info in redis and got:

In [9]: datetime.utcfromtimestamp(1627824019.4668603)
Out[9]: datetime.datetime(2021, 8, 1, 13, 20, 19, 466860)

which is correct, UTC+8 's 21:00 is UTC 's 13:00.

so why when flower show a utc time in UTC+8 not plus 8 but minus?

To Reproduce set both worker and flower with CELERY_TIMEZONE, request a task, and got wrong time show in flower.

Expected behavior right time.

System information Output of python -c 'from flower.utils import bugreport; print(bugreport())' command

flower   -> flower:1.0.0 tornado:6.1 humanize:3.10.0
software -> celery:5.1.2 (sun-harmonics) kombu:5.1.0 py:3.9.6
            billiard:3.6.4.0 py-amqp:5.0.6
platform -> system:Linux arch:64bit
            kernel version:5.4.0-80-generic imp:CPython
loader   -> celery.loaders.app.AppLoader
settings -> transport:amqp results:disabled

deprecated_settings: None

PaleNeutron avatar Aug 01 '21 13:08 PaleNeutron

I have the same issue. It seems like this could have been resolved by #1162 and is just not released yet (fix from November '21, release from July '21). Did you check this already?

Edit: it seems resolved for me when using version 0.9.7 of the docker image.

Edit 2: Only the docker logs are now fixed and show the correct time. In the browser, flower still shows the wrong timezone.

felixriese avatar Apr 11 '22 12:04 felixriese

Update: With 1.0.0, I am pretty sure this worked for me:

  flower:
    image: mher/flower:1.2.0
    command: celery flower
    ports:
      - 5000:5000
    environment:
      - CELERY_TIMEZONE=Europe/Berlin
      - CELERY_ENABLE_UTC=True
      - TZ=Europe/Berlin

Now with 1.2.0, it doesn't anymore. Any ideas what else to try?

felixriese avatar Aug 17 '22 14:08 felixriese

Update: With 1.0.0, I am pretty sure this worked for me:

  flower:
    image: mher/flower:1.2.0
    command: celery flower
    ports:
      - 5000:5000
    environment:
      - CELERY_TIMEZONE=Europe/Berlin
      - CELERY_ENABLE_UTC=True
      - TZ=Europe/Berlin

Now with 1.2.0, it doesn't anymore. Any ideas what else to try?

This guy here figured it out. It took me sometime to understand what he is saying but it turned out he is right. His reference is on point as well. https://stackoverflow.com/questions/73566846/celery-flower-web-received-and-started-timezone-not-in-my-set-time-zone-still-ut

To fix it, in my case, the container env CELERY_TIMEZONE CELERY_ENABLE_UTC TZ didn't do much. The TZ setting on the other hand messed up with the clock so I removed them all along. And then in the worker file (worker.py) put the setting there:

celery = Celery('tasks', broker=CELERY_BROKER_URL, backend=CELERY_RESULT_BACKEND, ) celery.conf['CELERY_TIMEZONE'] = "Asia/Shanghai"

Also in the docker compose command it should be the following, (the -A parameter is the name of the worker file as in worker.py above):

flower: command: ['celery', '-A', 'worker', 'flower']

This will fix both the task view and the detail view.

bropuffshroom avatar Jan 04 '23 05:01 bropuffshroom

The TZ setting on the other hand messed up with the clock so I removed them all along.

Removing TZ in the docker-compose file for the flower service brings the correct timezone in the UI, but the logs show now a wrong time.

felixriese avatar Jan 04 '23 11:01 felixriese

Settings.py

CELERY_TIMEZONE = 'Asia/Kolkata'
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Asia/Kolkata'
USE_TZ = True

Worker+ BEAT

celery -A APP_NAME worker --pool=prefork --concurrency=5 --autoscale=10,1 --beat -l info

Flower With Redis broker

celery -A APP_NAME --broker=redis://127.0.0.1:6379 flower --address=127.0.0.1 --port=5555

akumars1 avatar Apr 07 '23 19:04 akumars1