An open source, non-profit web search engine
feat: add crawler version tracking to batch uploads
thiswillbeyourgithub (aider)bc46c413efca
diff --git a/mwmbl/crawl.py b/mwmbl/crawl.pyindex 0d5b04e..86284f0 100644--- a/mwmbl/crawl.py+++ b/mwmbl/crawl.py@@ -11,6 +11,8 @@ import requestsfrom django.conf import settingsfrom redis import Redis+CRAWLER_VERSION: str = "0.2.0"+from mwmbl.crawler.env_vars import CRAWLER_WORKERS, CRAWL_THREADS, CRAWL_DELAY_SECONDSfrom mwmbl.rankeval.evaluation.remote_index import RemoteIndexfrom mwmbl.redis_url_queue import RedisURLQueue@@ -138,7 +140,12 @@ def process_batch():results.append(result)logger.debug("Result", result)js_timestamp = int(time.time() * 1000)- batch = HashedBatch.parse_obj({"user_id_hash": user_id, "timestamp": js_timestamp, "items": results})+ batch = HashedBatch.parse_obj({+ "user_id_hash": user_id,+ "timestamp": js_timestamp,+ "items": results,+ "crawler_version": CRAWLER_VERSION+ })record_urls_in_database([batch], url_queue)# Push the batch into the Redis queuediff --git a/mwmbl/crawler/app.py b/mwmbl/crawler/app.pyindex 198e94e..a50330e 100644--- a/mwmbl/crawler/app.py+++ b/mwmbl/crawler/app.py@@ -15,6 +15,7 @@ from redis import Redisfrom mwmbl.crawler.batch import Batch, NewBatchRequest, HashedBatch, Results, PostResultsResponse, Errorfrom mwmbl.crawler.env_vars import REDIS_URL+from mwmbl.crawl import CRAWLER_VERSIONfrom mwmbl.crawler.stats import MwmblStats, StatsManagerfrom mwmbl.database import Databasefrom mwmbl.indexer.batch_cache import BatchCache@@ -86,7 +87,12 @@ def create_router(batch_cache: BatchCache, queued_batches: RedisURLQueue, versio# Using an approach from https://stackoverflow.com/a/30476450now = datetime.now(timezone.utc)epoch_time = (now - datetime(1970, 1, 1, tzinfo=timezone.utc)).total_seconds()- hashed_batch = HashedBatch(user_id_hash=user_id_hash, timestamp=epoch_time, items=batch.items)+ hashed_batch = HashedBatch(+ user_id_hash=user_id_hash,+ timestamp=epoch_time,+ items=batch.items,+ crawler_version=CRAWLER_VERSION+ )stats_manager.record_batch(hashed_batch)diff --git a/mwmbl/crawler/batch.py b/mwmbl/crawler/batch.pyindex 440f725..303338e 100644--- a/mwmbl/crawler/batch.py+++ b/mwmbl/crawler/batch.py@@ -58,6 +58,7 @@ class HashedBatch(Schema):user_id_hash: strtimestamp: floatitems: list[Item]+ crawler_version: Optional[str] = Noneclass Result(Schema):