mirror of
https://github.com/zulip/zulip.git
synced 2025-11-11 09:27:43 +00:00
Change timezone-naive datetimes to use timezone.now() where safe to do so.
Change timezone-naive datetimes to use timezone.now() in cases where there is no change in behavior.
This commit is contained in:
@@ -18,6 +18,7 @@ sys.path.append('/home/zulip/deployments/current')
|
|||||||
import scripts.lib.setup_path_on_import
|
import scripts.lib.setup_path_on_import
|
||||||
|
|
||||||
import django
|
import django
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
os.environ['DJANGO_SETTINGS_MODULE'] = "zproject.settings"
|
os.environ['DJANGO_SETTINGS_MODULE'] = "zproject.settings"
|
||||||
sys.path.append('/home/zulip/deployments/current')
|
sys.path.append('/home/zulip/deployments/current')
|
||||||
@@ -50,13 +51,13 @@ def report(state, short_msg, too_old=None):
|
|||||||
|
|
||||||
exit(states[state])
|
exit(states[state])
|
||||||
|
|
||||||
now = datetime.datetime.utcnow()
|
now = timezone.now()
|
||||||
|
|
||||||
all_users = UserActivity.objects.filter(query__in=["get_events_backend", "/api/v1/events"],
|
all_users = UserActivity.objects.filter(query__in=["get_events_backend", "/api/v1/events"],
|
||||||
client__name="zephyr_mirror")
|
client__name="zephyr_mirror")
|
||||||
new_inactive_users = [user for user in all_users if user.last_visit.replace(tzinfo=None) <
|
new_inactive_users = [user for user in all_users if user.last_visit <
|
||||||
now - datetime.timedelta(minutes=10)]
|
now - datetime.timedelta(minutes=10)]
|
||||||
old_inactive_users = [user for user in new_inactive_users if user.last_visit.replace(tzinfo=None) <
|
old_inactive_users = [user for user in new_inactive_users if user.last_visit <
|
||||||
now - datetime.timedelta(minutes=60)]
|
now - datetime.timedelta(minutes=60)]
|
||||||
recently_inactive_users = set(new_inactive_users) - set(old_inactive_users)
|
recently_inactive_users = set(new_inactive_users) - set(old_inactive_users)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import logging
|
import logging
|
||||||
import traceback
|
import traceback
|
||||||
@@ -38,10 +40,10 @@ class _RateLimitFilter(object):
|
|||||||
if not duplicate:
|
if not duplicate:
|
||||||
cache.set(key, 1, rate)
|
cache.set(key, 1, rate)
|
||||||
else:
|
else:
|
||||||
min_date = datetime.now() - timedelta(seconds=rate)
|
min_date = timezone.now() - timedelta(seconds=rate)
|
||||||
duplicate = (self.last_error >= min_date)
|
duplicate = (self.last_error >= min_date)
|
||||||
if not duplicate:
|
if not duplicate:
|
||||||
self.last_error = datetime.now()
|
self.last_error = timezone.now()
|
||||||
|
|
||||||
return not duplicate
|
return not duplicate
|
||||||
|
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ in a while.
|
|||||||
# To be really conservative while we don't have user timezones or
|
# To be really conservative while we don't have user timezones or
|
||||||
# special-casing for companies with non-standard workweeks, only
|
# special-casing for companies with non-standard workweeks, only
|
||||||
# try to send mail on Tuesdays, Wednesdays, and Thursdays.
|
# try to send mail on Tuesdays, Wednesdays, and Thursdays.
|
||||||
if datetime.datetime.utcnow().weekday() not in VALID_DIGEST_DAYS:
|
if timezone.now().weekday() not in VALID_DIGEST_DAYS:
|
||||||
return
|
return
|
||||||
|
|
||||||
deployment_realms = realms_for_this_deployment()
|
deployment_realms = realms_for_this_deployment()
|
||||||
|
|||||||
Reference in New Issue
Block a user