Skip to content

Commit c4e4a86

Browse files
committed
update tha gorkster
1 parent 310a825 commit c4e4a86

3 files changed

Lines changed: 27 additions & 16 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = "2024"
77
[dependencies]
88
tokio = { version = "1", features = ["full"] }
99
bsky-sdk = "0.1"
10-
rocketman = "0.2.3"
10+
rocketman = "0.2.5"
1111
metrics = "0.24.2"
1212
metrics-exporter-prometheus = "0.17.0"
1313
tracing = "0.1"

src/main.rs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ async fn main() {
8181
"app.bsky.feed.post".to_string(),
8282
Box::new(MyCoolIngestor::new(agent.clone())),
8383
);
84+
let ingestors = Arc::new(ingestors);
8485

8586
// tracks the last message we've processed
8687
let cursor: Arc<Mutex<Option<u64>>> = Arc::new(Mutex::new(load_cursor().await));
@@ -89,19 +90,29 @@ async fn main() {
8990
let msg_rx = jetstream.get_msg_rx();
9091
let reconnect_tx = jetstream.get_reconnect_tx();
9192

92-
// spawn a task to process messages from the queue.
93-
// this is a simple implementation, you can use a more complex one based on needs.
94-
let c_cursor = cursor.clone();
95-
tokio::spawn(async move {
96-
while let Ok(message) = msg_rx.recv_async().await {
97-
if let Err(e) =
98-
handler::handle_message(message, &ingestors, reconnect_tx.clone(), c_cursor.clone())
99-
.await
100-
{
101-
eprintln!("Error processing message: {}", e);
102-
};
103-
}
104-
});
93+
// spawn 10 tasks to process messages from the queue concurrently
94+
for i in 0..10 {
95+
let msg_rx_clone = msg_rx.clone();
96+
let ingestors_clone = Arc::clone(&ingestors);
97+
let reconnect_tx_clone = reconnect_tx.clone();
98+
let c_cursor = cursor.clone();
99+
100+
tokio::spawn(async move {
101+
info!("Starting worker thread {}", i);
102+
while let Ok(message) = msg_rx_clone.recv_async().await {
103+
if let Err(e) = handler::handle_message(
104+
message,
105+
&ingestors_clone,
106+
reconnect_tx_clone.clone(),
107+
c_cursor.clone(),
108+
)
109+
.await
110+
{
111+
eprintln!("Error processing message in worker {}: {}", i, e);
112+
};
113+
}
114+
});
115+
}
105116

106117
let c_cursor = cursor.clone();
107118
tokio::spawn(async move {

0 commit comments

Comments
 (0)