Skip to content

Commit

Permalink
Add trending track last completion to health check (#1294)
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondjacobson committed Mar 11, 2021
1 parent ba56bec commit f2b02fe
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
12 changes: 11 additions & 1 deletion discovery-provider/src/queries/get_health.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import logging
import os
import time

from src.models import Block, IPLDBlacklistBlock
from src.monitors import monitors, monitor_names
from src.utils import helpers, redis_connection, web3_provider, db_session
from src.utils.config import shared_config
from src.utils.redis_constants import latest_block_redis_key, \
latest_block_hash_redis_key, most_recent_indexed_block_hash_redis_key, most_recent_indexed_block_redis_key, \
most_recent_indexed_ipld_block_redis_key, most_recent_indexed_ipld_block_hash_redis_key
most_recent_indexed_ipld_block_redis_key, most_recent_indexed_ipld_block_hash_redis_key, \
trending_tracks_last_completion_redis_key


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -148,6 +150,13 @@ def get_health(args, use_redis_cache=True):
latest_indexed_block_num = db_block_state["number"] or 0
latest_indexed_block_hash = db_block_state["blockhash"]

trending_tracks_last_completion = redis.get(
trending_tracks_last_completion_redis_key
)
trending_tracks_age_sec = \
(int(time.time()) - int(trending_tracks_last_completion)) \
if trending_tracks_last_completion else None

# Get system information monitor values
sys_info = monitors.get_monitors([
MONITORS[monitor_names.database_size],
Expand All @@ -171,6 +180,7 @@ def get_health(args, use_redis_cache=True):
"blockhash": latest_indexed_block_hash
},
"git": os.getenv("GIT_SHA"),
"trending_tracks_age_sec": trending_tracks_age_sec,
**sys_info
}

Expand Down
3 changes: 3 additions & 0 deletions discovery-provider/src/tasks/index_trending.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from src.tasks.celery_app import celery
from src.queries.get_trending_tracks import make_trending_cache_key, generate_unpopulated_trending
from src.utils.redis_cache import pickle_and_set
from src.utils.redis_constants import trending_tracks_last_completion_redis_key

logger = logging.getLogger(__name__)
time_ranges = ["week", "month", "year"]
Expand Down Expand Up @@ -41,6 +42,8 @@ def index_trending(self, db, redis):
update_end = time.time()
update_total = update_end - update_start
logger.info(f"index_trending.py | Finished indexing trending in {update_total} seconds")
# Update cache key to track the last time trending finished indexing
redis.set(trending_tracks_last_completion_redis_key, int(update_end))

######## CELERY TASKS ########
@celery.task(name="index_trending", bind=True)
Expand Down
1 change: 1 addition & 0 deletions discovery-provider/src/utils/redis_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
most_recent_indexed_block_hash_redis_key = 'most_recently_indexed_block_hash_from_db'
most_recent_indexed_ipld_block_redis_key = 'most_recent_indexed_ipld_block_redis_key'
most_recent_indexed_ipld_block_hash_redis_key = 'most_recent_indexed_ipld_block_hash_redis_key'
trending_tracks_last_completion_redis_key = 'trending:tracks:last-completion'

0 comments on commit f2b02fe

Please sign in to comment.