forked from
microcosm.blue/Allegedly
Server tools to backfill, tail, mirror, and verify PLC logs
1use serde::Deserialize;
2
3mod backfill;
4mod client;
5mod plc_pg;
6mod poll;
7mod weekly;
8
9pub use backfill::week_to_pages;
10pub use client::CLIENT;
11pub use plc_pg::Db;
12pub use poll::{get_page, poll_upstream};
13pub use weekly::{Week, pages_to_weeks};
14
15pub type Dt = chrono::DateTime<chrono::Utc>;
16
17/// One page of PLC export
18///
19/// Expected to have up to around 1000 lines of raw json ops
20#[derive(Debug)]
21pub struct ExportPage {
22 pub ops: Vec<String>,
23}
24
25impl ExportPage {
26 pub fn is_empty(&self) -> bool {
27 self.ops.is_empty()
28 }
29}
30
31/// A fully-deserialized plc operation
32///
33/// including the plc's wrapping with timestmap and nullified state
34#[derive(Debug, Deserialize)]
35#[serde(rename_all = "camelCase")]
36pub struct Op<'a> {
37 pub did: &'a str,
38 pub cid: &'a str,
39 pub created_at: Dt,
40 pub nullified: bool,
41 #[serde(borrow)]
42 pub operation: &'a serde_json::value::RawValue,
43}
44
45/// Database primary key for an op
46#[derive(Debug, PartialEq)]
47pub struct OpKey {
48 pub did: String,
49 pub cid: String,
50}
51
52impl From<&Op<'_>> for OpKey {
53 fn from(Op { did, cid, .. }: &Op<'_>) -> Self {
54 Self {
55 did: did.to_string(),
56 cid: cid.to_string(),
57 }
58 }
59}
60
61pub fn bin_init(name: &str) {
62 use env_logger::{Builder, Env};
63 Builder::from_env(Env::new().filter_or("RUST_LOG", "info")).init();
64
65 log::info!(
66 r"
67
68 \ | | | |
69 _ \ | | -_) _` | -_) _` | | | | ({name})
70 _/ _\ _| _| \___| \__, | \___| \__,_| _| \_, | (v{})
71 ____| __/
72",
73 env!("CARGO_PKG_VERSION")
74 );
75}