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
32
33
34
use super::Bundle;
use async_trait::async_trait;
use snafu::Snafu;
use std::path::PathBuf;

#[derive(Snafu, Debug)]
pub enum Error {
  MissingBundleID,
  InternalPollerError {
    source: Box<dyn std::error::Error + Sync + Send>,
  },
  MismatchedBundleID {
    original_id: String,
    current_id: String,
  },
  UnpackError {
    source: std::io::Error,
  },
}

pub type Result<T, E = Error> = std::result::Result<T, E>;

pub enum PollResult {
  Skip,
  UpdateReady { etag: String },
  StaticUpdateReady { etag: Option<String>, path: PathBuf },
}

#[async_trait]
pub trait BundlePoller {
  async fn poll(&self, active_bundle: &Option<Bundle>) -> Result<PollResult>;

  async fn retrieve(&self, bundle_id: &str, path: PathBuf) -> Result<()>;
}