-
Notifications
You must be signed in to change notification settings - Fork 531
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
FastAPI server that handles provision requests (sky launch) in the background #2235
Comments
Seems to work well (with """Example: a FastAPI server that serves by calling `sky launch`.
Usage:
$ python server.py
# In another terminal:
$ curl localhost:8000
# Or:
$ for i in $(seq 32); do curl http://0.0.0.0:8000; done
"""
import uuid
import fastapi
import sky
app = fastapi.FastAPI()
def background_task(task_id: int):
task = sky.Task(run='echo hi').set_resources(
sky.Resources(cpus=2, use_spot=True))
sky.launch(
task,
cluster_name=f'sky-{task_id}',
down=True,
idle_minutes_to_autostop=1,
# Use these to avoid tailing logs:
detach_setup=True,
detach_run=True,
)
@app.get('/')
async def root(background_tasks: fastapi.BackgroundTasks):
task_id = str(uuid.uuid4())[-6:]
background_tasks.add_task(background_task, task_id)
return {'message': f'Background task `sky launch` started: {task_id}'}
def main():
import uvicorn
uvicorn.run(app, host='0.0.0.0', port=8000)
if __name__ == '__main__':
main() |
This issue is stale because it has been open 120 days with no activity. Remove stale label or comment or this will be closed in 10 days. |
This is being added in #2735 |
This comment was marked as outdated.
This comment was marked as outdated.
This issue is stale because it has been open 120 days with no activity. Remove stale label or comment or this will be closed in 10 days. |
This issue was closed because it has been stalled for 10 days with no activity. |
A user has the following setup:
sky launch
(detach setup + detach run) to provision a cluster to do some workWe should investigate this usage pattern and add a demo example, perhaps by using “background tasks”: https://fastapi.tiangolo.com/tutorial/background-tasks/
The text was updated successfully, but these errors were encountered: