Skip to content

Commit 6a87d49

Browse files
committed
basic streaming test
1 parent 49deff2 commit 6a87d49

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
bunny.webm
12
.build
23
Pulumi.*.yaml
34

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ build-native: .build
5050
build-docker: .build .build-docker
5151

5252
## retrieve the bunny video from the server
53+
# via https://en.wikipedia.org/wiki/Big_Buck_Bunny
5354
retrieve-bunny:
5455
scp kai@kai-server:/home/kai/bunny.webm .
5556

src/main.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import structlog
1111
import structlog.processors
1212

13-
from . import application, bsky, cache, worker
13+
from . import application, bsky, cache, worker, streaming
1414

1515
dotenv.load_dotenv()
1616
(app, limiter) = application.init()
@@ -45,6 +45,18 @@ async def cache_clear(request: fastapi.Request, suffix: str):
4545
return {"status": "ok"}
4646

4747

48+
@app.get("/streaming")
49+
@app.get("/streaming/")
50+
async def streaming_test():
51+
return fastapi.responses.StreamingResponse(streaming.testing(), media_type="text/plain")
52+
53+
54+
# @app.get("/video")
55+
# @app.get("/video/")
56+
# async def video():
57+
# return fastapi.responses.FileResponse("bunny.webm")
58+
59+
4860
@app.get("/bsky/{handle}/followers")
4961
@app.get("/bsky/{handle}/followers/")
5062
@limiter.limit("10/second")

src/streaming.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import asyncio
2+
import typing
3+
4+
5+
async def testing() -> typing.AsyncGenerator[str, None]:
6+
for i in range(100):
7+
await asyncio.sleep(1)
8+
yield f"Hello, world! {i}\n"

0 commit comments

Comments
 (0)