File: poll_events.rs

package info (click to toggle)
rust-octocrab 0.43.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,532 kB
  • sloc: makefile: 2
file content (31 lines) | stat: -rw-r--r-- 1,096 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use octocrab::{etag::Etagged, models::events::Event, Page};
use std::collections::VecDeque;

const DELAY_MS: u64 = 500;
const TRACKING_CAPACITY: usize = 200;

#[tokio::main]
async fn main() -> octocrab::Result<()> {
    let mut etag = None;
    let mut seen = VecDeque::with_capacity(TRACKING_CAPACITY);
    let octo = octocrab::instance();
    loop {
        let response: Etagged<Page<Event>> = octo.events().etag(etag).per_page(100).send().await?;
        if let Some(page) = response.value {
            for event in page {
                if !seen.contains(&event.id) {
                    println!(
                        "New event : id = {:?}, type = {:?}, time = {:?}",
                        event.id, event.r#type, event.created_at,
                    );
                    if seen.len() == TRACKING_CAPACITY {
                        seen.pop_back();
                    }
                    seen.push_front(event.id);
                }
            }
        }
        etag = response.etag;
        tokio::time::sleep(tokio::time::Duration::from_millis(DELAY_MS)).await;
    }
}