Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TASK] Modify the apply endpoint in the REST API to an asynchronous interface. #2553

Closed
jieguangzhou opened this issue Oct 23, 2024 · 1 comment · Fixed by #2572
Closed
Assignees

Comments

@jieguangzhou
Copy link
Collaborator

jieguangzhou commented Oct 23, 2024

When a component we add triggers long-running jobs, it is unreasonable for the entire endpoint to wait for all tasks to complete before responding.

The endpoint should return a success message after applying the component, while the jobs continue to run in the background.

from fastapi import FastAPI, BackgroundTasks

app = FastAPI()

def _apply_component(info: dict):
    return events

    
def push_events(events):
    .....

@app.add('/db/apply', method='post')
async  def db_apply(info: t.Dict, id: str | None = None, background_tasks: BackgroundTasks =None):
    events = _apply_component(info)

    background_tasks.add_task(push_events, events)
    
    return {'status': 'ok'}
@blythed
Copy link
Collaborator

blythed commented Oct 24, 2024

Agreed. This is especially true in open-source. We also now have the ability to watch the log, even if the task is starting in the background.

@blythed blythed changed the title Modify the apply endpoint in the REST API to an asynchronous interface. [TASK] Modify the apply endpoint in the REST API to an asynchronous interface. Oct 25, 2024
@github-project-automation github-project-automation bot moved this from In Progress to Done in superduper-open-source Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants