Skip to content

Commit

Permalink
Try again
Browse files Browse the repository at this point in the history
  • Loading branch information
richardr1126 committed Jan 16, 2025
1 parent 8d3fd24 commit 77f620c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
11 changes: 2 additions & 9 deletions firehose/data_stream.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections import defaultdict
from datetime import datetime, timedelta
from datetime import datetime, timezone

from atproto import (
AtUri,
Expand All @@ -19,13 +19,6 @@
models.AppBskyFeedPost: models.ids.AppBskyFeedPost,
}

def is_healthy():
with db.connection_context():
state = SubscriptionState.get_or_none()
if not state or not state.last_indexed_at:
return False
return (datetime.now() - state.last_indexed_at) < timedelta(minutes=5)

def _get_ops_by_type(commit: models.ComAtprotoSyncSubscribeRepos.Commit) -> defaultdict:
"""
Processes a commit message and extracts operations of interest, grouping them by record type.
Expand Down Expand Up @@ -174,7 +167,7 @@ def on_message_handler(message: firehose_models.MessageFrame) -> None:
with db.atomic():
SubscriptionState.update(
cursor=commit.seq,
last_indexed_at=datetime.now()
last_indexed_at=datetime.now(timezone.utc),
).where(SubscriptionState.service == name).execute()


Expand Down
9 changes: 9 additions & 0 deletions firehose/health_check.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# health_check.py
from data_stream import is_healthy
from utils.logger import logger
from datetime import datetime, timedelta, timezone
from database import db, SubscriptionState

def is_healthy():
with db.connection_context():
state = SubscriptionState.get_or_none()
if not state or not state.last_indexed_at:
return False
return (datetime.now(timezone.utc) - state.last_indexed_at) < timedelta(minutes=5)

if __name__ == "__main__":
if is_healthy():
Expand Down

0 comments on commit 77f620c

Please sign in to comment.