Skip to content

Commit

Permalink
Fix rest apply route
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik4949 committed Dec 19, 2024
1 parent 2628411 commit bd88c34
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions superduper/rest/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,33 @@ def db_upload(raw: bytes = File(...), db: 'Datalayer' = DatalayerDependency()):
return {"component": component, "artifacts": blob_objects}

def _process_db_apply(db, component, id: str | None = None):
def _apply():
nonlocal component
component = Document.decode(component, db=db).unpack()
db.apply(component, force=True)

if id:
log_file = f"/tmp/{id}.log"
with redirect_stdout_to_file(log_file):
db.apply(component, force=True)
try:
_apply()
except Exception as e:
logging.error(f'Exception during application apply :: {e}')
raise
else:
db.apply(component, force=True)
try:
_apply()

except Exception as e:
logging.error(f'Exception during application apply :: {e}')
raise

@app.add('/describe_tables')
def describe_tables(db: 'Datalayer' = DatalayerDependency()):
return db.databackend.list_tables_or_collections()

@app.add('/db/apply', method='post')
async def db_apply(
def db_apply(
info: t.Dict,
background_tasks: BackgroundTasks,
id: str | None = 'test',
Expand All @@ -170,8 +184,8 @@ async def db_apply(
info['_variables']['output_prefix'] = CFG.output_prefix
info['_variables']['databackend'] = db.databackend.backend_name

component = Document.decode(info, db=db).unpack()
background_tasks.add_task(_process_db_apply, db, component, id)
#info = Document.decode(info, db=db).unpack()
background_tasks.add_task(_process_db_apply, db, info, id)
return {'status': 'ok'}

import subprocess
Expand Down

0 comments on commit bd88c34

Please sign in to comment.