Skip to content

Commit

Permalink
check if sig already computed in S3
Browse files Browse the repository at this point in the history
  • Loading branch information
luizirber committed Feb 5, 2025
1 parent f866b6c commit 1bc0bae
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion wort/blueprints/compute/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import csv
import os
from pathlib import Path

from flask import Blueprint, current_app, jsonify, render_template, url_for
import requests
Expand Down Expand Up @@ -29,10 +30,45 @@ def compute_sra(sra_id, recompute=False):
db.session.add(dataset)
db.session.commit()

if not recompute and dataset.computed is not None:
up_to_date = False
if not recompute:
if dataset.computed is not None:
up_to_date = True

if dataset.computed is None:
# check on S3 to see if it was computed and not updated in DB
import boto3
import botocore
conn = boto3.client("s3")
s3 = boto3.resource("s3")

key_path = Path("sigs") / f"{sra_id}.sig"
try:
obj = s3.Object("wort-sra", key_path)
obj.load()
except botocore.exceptions.ClientError as e:
if e.response["Error"]["Code"] == "404":
pass # Object does not exist yet
else:
# Something else has gone wrong
raise
else:
# The key already exists, update compute field in DB
dataset.computed = obj.last_modified
db.session.add(dataset)
db.session.commit()
# Remove from cache, will be refreshed from DB next time
# there is a view request for it
current_app.cache.delete(f"sra/{sra_id}")

up_to_date = True

if up_to_date:
return jsonify({"status": "Signature already calculated"}), 202

if recompute:
# Force recomputation of sketch,
# clean status from DB and remove from cache
dataset.computed = None
db.session.add(dataset)
db.session.commit()
Expand Down

0 comments on commit 1bc0bae

Please sign in to comment.