forked from
microcosm.blue/Allegedly
Server tools to backfill, tail, mirror, and verify PLC logs
1use allegedly::{ExportPage, poll_upstream};
2
3#[tokio::main]
4async fn main() {
5 // set to `None` to replay from the beginning of the PLC history
6 let after = Some(chrono::Utc::now());
7
8 // the PLC server to poll for new ops
9 let upstream = "https://plc.wtf/export".parse().unwrap();
10
11 // self-rate-limit (plc.directory's limit interval is 600ms)
12 let throttle = std::time::Duration::from_millis(300);
13
14 // pages are sent out of the poller via a tokio mpsc channel
15 let (tx, mut rx) = tokio::sync::mpsc::channel(1);
16
17 // spawn a tokio task to run the poller
18 tokio::task::spawn(poll_upstream(after, upstream, throttle, tx));
19
20 // receive pages of plc ops from the poller
21 while let Some(ExportPage { ops }) = rx.recv().await {
22 println!("received {} plc ops", ops.len());
23
24 for op in ops {
25 // in this example we're alerting when changes are found for one
26 // specific identity
27 if op.did == "did:plc:hdhoaan3xa3jiuq4fg4mefid" {
28 println!(
29 "Update found for {}! cid={}\n -> operation: {}",
30 op.did,
31 op.cid,
32 op.operation.get()
33 );
34 }
35 }
36 }
37}