-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
254 additions
and
77 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import asyncio | ||
import os | ||
import random | ||
from datetime import timedelta | ||
from typing import AsyncIterable | ||
|
||
from streamstore import S2 | ||
from streamstore.schemas import Record | ||
|
||
AUTH_TOKEN = os.getenv("S2_AUTH_TOKEN") | ||
MY_BASIN = os.getenv("MY_BASIN") | ||
MY_STREAM = os.getenv("MY_STREAM") | ||
|
||
|
||
async def records() -> AsyncIterable[Record]: | ||
num_records = random.randint(1, 1000) | ||
for _ in range(num_records): | ||
body_size = random.randint(1, 1000) | ||
if random.random() < 0.5: | ||
await asyncio.sleep(random.random() * 2.5) | ||
yield Record(body=os.urandom(body_size)) | ||
|
||
|
||
async def producer(): | ||
async with S2(auth_token=AUTH_TOKEN) as s2: | ||
stream = s2[MY_BASIN][MY_STREAM] | ||
async for output in stream.append_session_with_auto_batching( | ||
records=records(), | ||
max_records_per_batch=10, | ||
max_linger_per_batch=timedelta(milliseconds=5), | ||
): | ||
num_appended_records = output.end_seq_num - output.start_seq_num | ||
print(f"appended {num_appended_records} records") | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(producer()) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import asyncio | ||
import os | ||
|
||
from streamstore import S2 | ||
|
||
AUTH_TOKEN = os.getenv("S2_AUTH_TOKEN") | ||
|
Oops, something went wrong.