Skip to content

Commit

Permalink
ref(daily summary): Fix timezone (#66563)
Browse files Browse the repository at this point in the history
Using `floor_to_utc_day` made the timestamp always UTC midnight which
equates to PST 4pm - this wasn't caught in tests because the timestamp
was being passed in so this code path wasn't being hit. This should
prevent the resending each hour to only sending at 4pm at the user's
local time as intended.
  • Loading branch information
ceorourke authored Mar 11, 2024
1 parent 06c4982 commit 9db7b96
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/sentry/tasks/summaries/daily_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from sentry.types.activity import ActivityType
from sentry.types.group import GroupSubStatus
from sentry.types.integrations import ExternalProviders
from sentry.utils.dates import floor_to_utc_day, to_datetime, to_timestamp
from sentry.utils.dates import to_datetime, to_timestamp
from sentry.utils.outcomes import Outcome
from sentry.utils.query import RangeQuerySetWrapper

Expand All @@ -62,7 +62,7 @@
def schedule_organizations(timestamp: float | None = None, duration: int | None = None) -> None:
if timestamp is None:
# The time that the report was generated
timestamp = to_timestamp(floor_to_utc_day(timezone.now()))
timestamp = to_timestamp(timezone.now())

if duration is None:
# The total timespan that the task covers
Expand Down
17 changes: 17 additions & 0 deletions tests/sentry/tasks/test_daily_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,23 @@ def test_schedule_organizations(self, mock_prepare_summary_data):
[self.user.id],
)

@with_feature("organizations:daily-summary")
@mock.patch("sentry.tasks.summaries.daily_summary.prepare_summary_data")
def test_schedule_organizations_timing(self, mock_prepare_summary_data):
with self.tasks(), freeze_time("2024-03-06 23:15:00"): # 3:15PM PST
schedule_organizations()
assert mock_prepare_summary_data.delay.call_count == 0

with self.tasks(), freeze_time("2024-03-07 00:00:00"): # 4PM PST
schedule_organizations()
assert mock_prepare_summary_data.delay.call_count == 1

with self.tasks(), freeze_time("2024-03-07 01:00:00"): # 5PM PST
schedule_organizations()
assert (
mock_prepare_summary_data.delay.call_count == 1
) # note this didn't fire again, it just didn't increase from before

def test_build_summary_data(self):
self.populate_event_data()
summary = build_summary_data(
Expand Down

0 comments on commit 9db7b96

Please sign in to comment.