Skip to content

Commit 3a0ad45

Browse files
ted kaemmingmattrobenolt
authored andcommitted
Merge pull request #2543 from getsentry/log-digest-state-error
Catch and log digest state exceptions.
1 parent 8a99ed4 commit 3a0ad45

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

src/sentry/digests/backends/base.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ def load(options):
1717
}
1818

1919

20+
class InvalidState(Exception):
21+
"""
22+
An error that is raised when an action cannot be performed on a
23+
timeline in it's current state.
24+
"""
25+
26+
2027
class Backend(object):
2128
"""
2229
A digest backend coordinates the addition of records to timelines, as well

src/sentry/digests/backends/redis.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
Record,
1717
ScheduleEntry,
1818
)
19-
from sentry.digests.backends.base import Backend
19+
from sentry.digests.backends.base import (
20+
Backend,
21+
InvalidState,
22+
)
2023
from sentry.utils.cache import Lock
2124
from sentry.utils.redis import (
2225
check_cluster_versions,
@@ -398,8 +401,12 @@ def digest(self, key, minimum_delay=None):
398401
connection = self.cluster.get_local_client_for_key(timeline_key)
399402

400403
with Lock(timeline_key, nowait=True, timeout=30):
404+
# Check to ensure the timeline is in the correct state ("ready")
405+
# before sending. This acts as a throttling mechanism to prevent
406+
# sending a digest before it's next scheduled delivery time in a
407+
# race condition scenario.
401408
if connection.zscore(make_schedule_key(self.namespace, SCHEDULE_STATE_READY), key) is None:
402-
raise Exception('Cannot digest timeline, timeline is not in the ready state.')
409+
raise InvalidState('Timeline is not in the ready state.')
403410

404411
with connection.pipeline() as pipeline:
405412
pipeline.watch(digest_key) # This shouldn't be necessary, but better safe than sorry?

src/sentry/tasks/digests.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import time
55

66
from sentry.digests import get_option_key
7+
from sentry.digests.backends.base import InvalidState
78
from sentry.digests.notifications import (
89
build_digest,
910
split_key,
@@ -58,8 +59,13 @@ def deliver_digest(key, schedule_timestamp=None):
5859
project,
5960
get_option_key(plugin.get_conf_key(), 'minimum_delay')
6061
)
61-
with digests.digest(key, minimum_delay=minimum_delay) as records:
62-
digest = build_digest(project, records)
62+
63+
try:
64+
with digests.digest(key, minimum_delay=minimum_delay) as records:
65+
digest = build_digest(project, records)
66+
except InvalidState as error:
67+
logger.info('Skipped digest delivery: %s', error, exc_info=True)
68+
return
6369

6470
if digest:
6571
plugin.notify_digest(project, digest)

0 commit comments

Comments
 (0)