Skip to content

Correct calculation of application current time with timezone - #4173

Merged
georgepsarakis merged 2 commits into
celery:masterfrom
georgepsarakis:bug/4160_incorrect_timezone_app_now
Jul 28, 2017
Merged

georgepsarakis merged 2 commits into
celery:masterfrom
georgepsarakis:bug/4160_incorrect_timezone_app_now

Conversation

@georgepsarakis

@georgepsarakis georgepsarakis commented Jul 28, 2017 •

Copy link
Copy Markdown
Contributor

Description

Incorrect application current time calculation was introduced with https://github.com/celery/celery/pull/3867/files .

  • Use datetime.astimezone to adjust current time in App.now.

Closes #4160 .

@georgepsarakis

Copy link
Copy Markdown
Contributor Author

@rtpg @thedrow @auvipy can you please review this change? It seems that it has many side-effects. See also celery/kombu#774 and probably #4169 .

Comment thread celery/app/base.py Outdated

def now(self):
"""Return the current time and date as a datetime."""
from celery.utils.time import to_utc

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we importing stuff here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No good reason. Fixed in latest commit, thanks.

@rtpg

rtpg commented Jul 28, 2017

Copy link
Copy Markdown

At least for the changes to now, that seems right to me

@georgepsarakis
georgepsarakis merged commit 87b263b into celery:master Jul 28, 2017
@georgepsarakis
georgepsarakis deleted the bug/4160_incorrect_timezone_app_now branch July 28, 2017 20:14
@georgepsarakis

Copy link
Copy Markdown
Contributor Author

Thank you both for the reviews 😄 .

@steve-gregory

Copy link
Copy Markdown

I believe this PR should also close #4145 ?

@marco-silva0000

Copy link
Copy Markdown

maybe this is also related #4041

however I think there is still a bug somewhere, but may not be directly related in all issues. please see my comment there with a small explanation

@razerraz

razerraz commented Aug 7, 2017

Copy link
Copy Markdown

It seems this commit don't resolve everything :
celery/django-celery-beat#70 (comment)

pztrick pushed a commit to pztrick/django-celery-beat that referenced this pull request Aug 8, 2017
…son, made timezone aware. Fixes crontab schedules after celery/celery#4173.
@nooperpudd

Copy link
Copy Markdown

hopefully release this pull request as soon as possible.

@chuanma chuanma left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR doesn't update automated test. Does Celery have a unit test to guard against this kind of bug?

I just started using Celery, and this bug screwed me a couple of days, wondering why Celery doesn't run tasks at proper time.

@ldsink

ldsink commented Aug 11, 2017 •

Copy link
Copy Markdown
Contributor

This PR solve our problems. Please release a fix version for 4.1.x series as soon as possible.

@rtpg

rtpg commented Aug 14, 2017

Copy link
Copy Markdown

@chuanma This does update some unit tests that cover the calculation of "now". Because of the low-level nature of this bug, higher level tests won't catch this bug (Because ultimately a lot of code relied on this code path for determining the time).

When everyone holds the same broken clock, hard to notice that it's broken. Luckily, it also means there's usually just one place to fix

canassa pushed a commit to canassa/celery that referenced this pull request Aug 21, 2017
…#4173)

* Use datetime.astimezone to adjust current time

* Remove import statements from Celery.now
canassa pushed a commit to canassa/celery that referenced this pull request Aug 21, 2017
…#4173)

* Use datetime.astimezone to adjust current time

* Remove import statements from Celery.now
@pieterdd

Copy link
Copy Markdown

Any chance of a 4.1.1 hotfix release happening? We recently upgraded from v4.0.2 to v4.1, thinking a minor version release from two months ago would have been a safe upgrade. But due to our reliance on crontab for some of our periodic tasks, this is impacting us.

@jobec

jobec commented Sep 21, 2017

Copy link
Copy Markdown

We downgraded to v4.0.2 because of this issue...

@alexmic

alexmic commented Oct 3, 2017

Copy link
Copy Markdown

Same here, 4.1 series broke our scheduling because our timezone is Europe/London.

@JoshYuJump

Copy link
Copy Markdown

Wondering when to release the PR.

@JoshYuJump

Copy link
Copy Markdown

hopefully release this pull request as soon as possible.

@fanjindong

fanjindong commented Oct 20, 2017 via email

Copy link
Copy Markdown

@JoshYuJump

Copy link
Copy Markdown

@fanjindong , I thank the PR has fixed it.

@timosir

timosir commented Oct 23, 2017

Copy link
Copy Markdown

@JoshYuJump
CELERY_TIMEZONE = 'UTC'
CELERY_ENABLE_UTC = True
CELERY_TIMEZONE = 'Asia/Shanghai'
CELERYBEAT_SCHEDULE = {
'cc':{
'task':'operate.check_hangqing_sts',
'schedule': crontab(minute="38",hour='15')
}
}

celery --version
4.1.0 (latentcall)

At this point in my setting, do not work??

@timosir

timosir commented Oct 23, 2017

Copy link
Copy Markdown

TIME_ZONE='Asia/Shanghai'
CELERY_ENABLE_UTC = False
CELERY_TIMEZONE = 'Asia/Shanghai'
CELERYBEAT_SCHEDULE = {
'cc':{
'task':'operate.check_hangqing_sts',
'schedule': crontab(minute="10",hour='14')
}
}

celery --version
4.1.0 (latentcall)

At this point in my setting, do not work??

@fanjindong

fanjindong commented Oct 23, 2017 via email

Copy link
Copy Markdown

@jobec

jobec commented Jan 3, 2018

Copy link
Copy Markdown

Any chance of releasing a new version for this any time soon?

@auvipy

auvipy commented Jan 4, 2018

Copy link
Copy Markdown
Member

yes version 4.2 is due in January 2018

@xycloud

xycloud commented Jan 17, 2018

Copy link
Copy Markdown

that is really a super bug....
hope celery can make more test before release

@auvipy

auvipy commented Jan 17, 2018

Copy link
Copy Markdown
Member

@xycloud celery is a volunteer driven project and relies on the effort of the volunteers like you and me. please help with contributions in any form which is useful. we really lack enough resource to manage this huge project.

@xycloud

xycloud commented Jan 17, 2018

Copy link
Copy Markdown

yes, thanks celery sincerely, its really a awesomeness.
maybe celery can accept some donations if possible

@auvipy

auvipy commented Jan 17, 2018

Copy link
Copy Markdown
Member

yes but we had plans for donation but failed to reach our goal.

@jobec

jobec commented Jun 5, 2018

Copy link
Copy Markdown

It looks like this did not make it into version 4.1.1?

@thedrow

thedrow commented Jun 5, 2018

Copy link
Copy Markdown
Contributor

I didn't cherry pick this into 4.1.1.
Use 4.2 when it is released.

Photonios added a commit to SectorLabs/celery that referenced this pull request Feb 21, 2019
…#4173)

* Use datetime.astimezone to adjust current time

* Remove import statements from Celery.now

# Conflicts:
#	celery/app/base.py
Oleh929216 added a commit to Oleh929216/Django-beat that referenced this pull request Jan 30, 2025
…son, made timezone aware. Fixes crontab schedules after celery/celery#4173.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.