Skip to content

Commit

Permalink
Should load the runs/checks at the startup
Browse files Browse the repository at this point in the history
Signed-off-by: popcorny <[email protected]>
  • Loading branch information
popcornylu committed Apr 3, 2024
1 parent a652c4c commit 2887b14
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
12 changes: 7 additions & 5 deletions recce/dbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ def load(cls, **kwargs):
review_mode=is_review_mode,
)

if state_file:
state = RecceState.from_file(state_file)
dbt_context.import_state(state)

# Load the artifacts from the state file or `target` and `target-base` directory
if is_review_mode:
if state_file:
Expand Down Expand Up @@ -573,14 +577,12 @@ def _load_artifact(path):

return state

def import_state(self, json_content):
def import_state(self, import_state: RecceState):
"""
Import the state from a JSON string. It would
Import the state. It would
1. Merge runs
2. Merge checks
"""
import_state = RecceState.model_validate_json(json_content)
checks = CheckDAO().list()
runs = RunDAO().list()
current_check_ids = [str(c.check_id) for c in checks]
Expand All @@ -607,7 +609,7 @@ def import_state(self, json_content):
load_runs(runs)
load_checks(checks)

return runs, checks
return import_runs, import_checks


dbt_context: Optional[DBTContext] = None
Expand Down
5 changes: 4 additions & 1 deletion recce/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,13 @@ async def export_handler():

@app.post("/api/import", status_code=200)
async def import_handler(file: UploadFile):
from recce.state import RecceState

dbt_context = default_dbt_context()
try:
content = await file.read()
import_runs, import_checks = dbt_context.import_state(content)
state = RecceState.from_json(content)
import_runs, import_checks = dbt_context.import_state(state)

return {"runs": import_runs, "checks": import_checks}
except ValidationError as e:
Expand Down

0 comments on commit 2887b14

Please sign in to comment.