File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change 5
5
import re
6
6
import tempfile
7
7
from datetime import datetime
8
+ from datetime import timedelta
8
9
10
+ import pytz
9
11
import redis
10
12
import structlog
11
13
import zstandard as zstd
@@ -368,7 +370,7 @@ def get_suites(self, repository):
368
370
suites = self .redis .smembers (KEY_SUITES .format (repository = repository ))
369
371
return sorted (map (lambda x : x .decode ("utf-8" ), suites ))
370
372
371
- def ingest_available_reports (self , repository ):
373
+ def ingest_available_reports (self , repository , until = None ):
372
374
"""
373
375
Ingest all the available reports for a repository
374
376
"""
@@ -377,8 +379,13 @@ def ingest_available_reports(self, repository):
377
379
REGEX_BLOB = re .compile (
378
380
r"^{}/(\w+)/([\w\-]+):([\w\-]+).json.zstd$" .format (repository )
379
381
)
382
+ now = datetime .utcnow ().replace (tzinfo = pytz .UTC )
380
383
for blob in self .bucket .list_blobs (prefix = repository ):
381
384
385
+ if isinstance (until , timedelta ) and (now - blob .time_created ) >= until :
386
+ logger .debug (f"Skipping old blob { blob } " )
387
+ continue
388
+
382
389
# Get changeset from blob name
383
390
match = REGEX_BLOB .match (blob .name )
384
391
if match is None :
Original file line number Diff line number Diff line change
1
+ # -*- coding: utf-8 -*-
2
+ # This Source Code Form is subject to the terms of the Mozilla Public
3
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
4
+ # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
+
6
+ import os
7
+
8
+ import redis
9
+
10
+
11
+ def cleanup (client , prefix ):
12
+ nb , memory = 0 , 0
13
+ for key in client .keys (f"{ prefix } :*" ):
14
+ if key .endswith (b"all:all" ):
15
+ continue
16
+
17
+ key_memory = client .memory_usage (key )
18
+ nb += 1
19
+ memory += key_memory
20
+ print (f"Removing { key_memory } b for { key } " )
21
+
22
+ client .delete (key )
23
+
24
+ print (f"Removed { nb } keys for { memory } bytes" )
25
+
26
+
27
+ if __name__ == "__main__" :
28
+ client = redis .from_url (os .environ ["REDIS_URL" ])
29
+ cleanup (client , "overall:mozilla-central" )
You can’t perform that action at this time.
0 commit comments