Created
February 27, 2025 17:23
-
-
Save jezell/79572625da1485714f9d8a7fe112d06f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.cls(concurrency_limit=1, allow_concurrent_inputs=1) | |
class RoomProvisioner: | |
project_id: str = modal.parameter() | |
room_name: str = modal.parameter() | |
sandbox = None | |
@modal.web_endpoint() | |
def lookup(self): | |
if self.sandbox != None: | |
if self.sandbox.poll() != None: | |
self.sandbox = None | |
else: | |
return { | |
"url" : self.sandbox.tunnels()[8080].url | |
} | |
room = modal.App.lookup("room-server", create_if_missing=True) | |
sb = None | |
for s in modal.Sandbox.list(app_id=room.app_id, tags={"project_id":self.project_id, "room_name":self.room_name}): | |
sb = s | |
if sb != None: | |
self.sandbox = sb | |
else: | |
sb = modal.Sandbox.create("python3","cli.py", | |
app=room, | |
workdir="/src", | |
image=image, | |
secrets=[ | |
modal.Secret.from_name("custom-secret") | |
], | |
encrypted_ports=[8080] | |
) | |
sb.set_tags( | |
tags={ | |
"project_id": self.project_id, | |
"room_name": self.room_name | |
}) | |
self.sandbox = sb | |
return { | |
"url" : sb.tunnels()[8080].url | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment