in mozetl/graphics/graphics_telemetry_trends.py [0:0]
def finish(self):
# If we're doing a maximum backfill, remove points from the cache that are
# after the least recent data point that we newly queried.
if ForceMaxBackfill and len(self.newDataPoints):
stop_at = self.newDataPoints[-1]["start"]
last_index = None
for index, entry in enumerate(self.cache["trend"]):
if entry["start"] >= stop_at:
last_index = index
break
if last_index is not None:
self.cache["trend"] = self.cache["trend"][:last_index]
# Note: the backfill algorithm in DoUpdate() walks in reverse, so dates
# will be accumulated in descending order. The final list should be in
# ascending order, so we reverse.
self.cache["trend"] += self.newDataPoints[::-1]
text = json.dumps(self.cache)
print("Writing file {0}".format(self.local_path))
with open(self.local_path, "w") as fp:
fp.write(text)
if GCS_BUCKET is not None:
try:
bucket = storage_client.get_bucket(GCS_BUCKET)
blob = bucket.blob(os.path.join(GCS_PREFIX, self.name))
blob.upload_from_filename(self.local_path)
except Exception as e:
print("Failed gcs upload: {0}".format(e))