diff --git a/camdetect.py b/camdetect.py index 1865b10..b571235 100755 --- a/camdetect.py +++ b/camdetect.py @@ -56,6 +56,9 @@ CLOCK_SKEW_TOLERANCE = timedelta(seconds=3) # Percentage of blocks active to consider movement in whole frame THRESHOLD_RATIO = int(os.getenv("THRESHOLD_RATIO", "5")) +# Days to keep events +TTL_DAYS = int(os.getenv("TTL_DAYS", "3")) + CHUNK_BOUNDARY = b"\n--frame\nContent-Type: image/jpeg\n\n" hist_active_blocks_ratio = Histogram( @@ -560,6 +563,8 @@ async def setup_db(app, loop): app.ctx.coll.create_index([ ("source", pymongo.ASCENDING), ("@timestamp", pymongo.ASCENDING)], unique=True) + app.ctx.coll.create_index( + "@timestamp", expireAfterSeconds=TTL_DAYS*60*60*24) app.ctx.last_frame = None app.ctx.event_frame = asyncio.Event() app.ctx.event_id = None