Skip to content

armgit / mwmbl

Public Imported from GitHub
0

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.py
index 0d5b04e..86284f0 100644
--- a/mwmbl/crawl.py
+++ b/mwmbl/crawl.py
@@ -11,6 +11,8 @@ import requests
from django.conf import settings
from redis import Redis
+CRAWLER_VERSION: str = "0.2.0"
+
from mwmbl.crawler.env_vars import CRAWLER_WORKERS, CRAWL_THREADS, CRAWL_DELAY_SECONDS
from mwmbl.rankeval.evaluation.remote_index import RemoteIndex
from 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 queue
diff --git a/mwmbl/crawler/app.py b/mwmbl/crawler/app.py
index 198e94e..a50330e 100644
--- a/mwmbl/crawler/app.py
+++ b/mwmbl/crawler/app.py
@@ -15,6 +15,7 @@ from redis import Redis
from mwmbl.crawler.batch import Batch, NewBatchRequest, HashedBatch, Results, PostResultsResponse, Error
from mwmbl.crawler.env_vars import REDIS_URL
+from mwmbl.crawl import CRAWLER_VERSION
from mwmbl.crawler.stats import MwmblStats, StatsManager
from mwmbl.database import Database
from 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/30476450
now = 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.py
index 440f725..303338e 100644
--- a/mwmbl/crawler/batch.py
+++ b/mwmbl/crawler/batch.py
@@ -58,6 +58,7 @@ class HashedBatch(Schema):
user_id_hash: str
timestamp: float
items: list[Item]
+ crawler_version: Optional[str] = None
class Result(Schema):