mirror of
https://seed.radicle.dev/rad:zwTxygwuz5LDGBq255RA2CbNGrz8.git
synced 2026-11-29 06:40:31 +08:00
feat: make HTML refresh interval configurable
This commit is contained in:
@@ -238,6 +238,7 @@ impl QueuedCmd {
|
||||
ergo::Radicle::new().map_err(CibError::ergo)?,
|
||||
db,
|
||||
true,
|
||||
config.refresh_interval(),
|
||||
);
|
||||
if let Some(desc) = config.description() {
|
||||
page.set_description(desc);
|
||||
@@ -284,6 +285,7 @@ impl ProcessEventsCmd {
|
||||
ergo::Radicle::new().map_err(CibError::ergo)?,
|
||||
db,
|
||||
false,
|
||||
config.refresh_interval(),
|
||||
);
|
||||
if let Some(desc) = config.description() {
|
||||
page.set_description(desc);
|
||||
|
||||
@@ -14,6 +14,10 @@ pub struct ReportCmd {
|
||||
/// for describing the CI node instance.
|
||||
#[clap(long)]
|
||||
description: Option<String>,
|
||||
|
||||
/// Default refresh interval for generated HTML page.
|
||||
#[clap(long, default_value = "86400")]
|
||||
refresh_interval: usize,
|
||||
}
|
||||
|
||||
impl Leaf for ReportCmd {
|
||||
@@ -26,6 +30,7 @@ impl Leaf for ReportCmd {
|
||||
ergo::Radicle::new().map_err(CibToolError::Ergo)?,
|
||||
db,
|
||||
true,
|
||||
self.refresh_interval,
|
||||
);
|
||||
if let Some(desc) = &self.description {
|
||||
page.set_description(desc);
|
||||
|
||||
@@ -50,6 +50,9 @@ pub struct Config {
|
||||
#[serde(default = "default_queue_len_interval")]
|
||||
queue_len_interval: Duration,
|
||||
|
||||
#[serde(default = "default_refresh_interval")]
|
||||
refresh_interval: usize,
|
||||
|
||||
#[serde(default)]
|
||||
concurrent_adapters: Option<usize>,
|
||||
|
||||
@@ -71,6 +74,10 @@ fn default_update_job_cobs() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn default_refresh_interval() -> usize {
|
||||
300
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn load(filename: &Path) -> Result<Self, ConfigError> {
|
||||
let config = std::fs::read(filename).map_err(|e| ConfigError::read_config(filename, e))?;
|
||||
@@ -151,6 +158,10 @@ impl Config {
|
||||
self.update_job_cobs
|
||||
}
|
||||
|
||||
pub fn refresh_interval(&self) -> usize {
|
||||
self.refresh_interval
|
||||
}
|
||||
|
||||
pub fn to_json(&self) -> Result<String, ConfigError> {
|
||||
serde_json::to_string_pretty(self).map_err(ConfigError::to_json)
|
||||
}
|
||||
|
||||
+28
-10
@@ -41,7 +41,6 @@ const BROKER_RSS: &str = "index.rss";
|
||||
const FAILURE_RSS: &str = "failed.rss";
|
||||
const UNFINISHED_RSS: &str = "unfinished.rss";
|
||||
const CSS: &str = include_str!("radicle-ci.css");
|
||||
const REFERESH_INTERVAL: &str = "5";
|
||||
const STATUS_JSON: &str = "status.json";
|
||||
|
||||
/// All possible errors returned from the status page module.
|
||||
@@ -108,8 +107,8 @@ impl PageData {
|
||||
StatusData::from(self).as_json()
|
||||
}
|
||||
|
||||
fn status_page_as_html(&self) -> Result<HtmlPage, PageError> {
|
||||
let mut doc = ReportPage::new(&self.node_alias);
|
||||
fn status_page_as_html(&self, refresh_interval: usize) -> Result<HtmlPage, PageError> {
|
||||
let mut doc = ReportPage::new(&self.node_alias, refresh_interval);
|
||||
if let Some(snippet) = &self.desc_snippet {
|
||||
doc.desc(snippet);
|
||||
}
|
||||
@@ -349,8 +348,14 @@ impl PageData {
|
||||
.with_text("unknown")
|
||||
}
|
||||
|
||||
fn per_repo_page_as_html(&self, rid: RepoId, alias: &str, timestamp: &str) -> HtmlPage {
|
||||
let mut doc = ReportPage::new(alias);
|
||||
fn per_repo_page_as_html(
|
||||
&self,
|
||||
rid: RepoId,
|
||||
alias: &str,
|
||||
timestamp: &str,
|
||||
refresh_interval: usize,
|
||||
) -> HtmlPage {
|
||||
let mut doc = ReportPage::new(alias, refresh_interval);
|
||||
doc.push(
|
||||
Element::new(Tag::P).with_child(
|
||||
Element::new(Tag::A)
|
||||
@@ -750,7 +755,7 @@ struct ReportPage {
|
||||
}
|
||||
|
||||
impl ReportPage {
|
||||
fn new(node_alias: &str) -> Self {
|
||||
fn new(node_alias: &str, refresh_interval: usize) -> Self {
|
||||
let mut page = HtmlPage::default();
|
||||
let title = format!("CI for Radicle node {node_alias}");
|
||||
page.push_to_head(Element::new(Tag::Title).with_text(&title));
|
||||
@@ -758,7 +763,7 @@ impl ReportPage {
|
||||
page.push_to_head(
|
||||
Element::new(Tag::Meta)
|
||||
.with_attribute("http-equiv", "refresh")
|
||||
.with_attribute("content", REFERESH_INTERVAL),
|
||||
.with_attribute("content", refresh_interval.to_string()),
|
||||
);
|
||||
page.push_to_body(Element::new(Tag::H1).with_text(&title));
|
||||
Self { page }
|
||||
@@ -853,6 +858,7 @@ pub struct StatusPage {
|
||||
node_alias: String,
|
||||
dirname: Option<PathBuf>,
|
||||
args: PageArgs,
|
||||
refresh_interval: usize,
|
||||
}
|
||||
|
||||
struct PageArgs {
|
||||
@@ -868,7 +874,13 @@ impl StatusPage {
|
||||
self.dirname = Some(dirname.into());
|
||||
}
|
||||
|
||||
pub fn new(run_rx: NotificationReceiver, radicle: ergo::Radicle, db: Db, once: bool) -> Self {
|
||||
pub fn new(
|
||||
run_rx: NotificationReceiver,
|
||||
radicle: ergo::Radicle,
|
||||
db: Db,
|
||||
once: bool,
|
||||
refresh_interval: usize,
|
||||
) -> Self {
|
||||
Self {
|
||||
node_alias: "".into(),
|
||||
dirname: None,
|
||||
@@ -879,6 +891,7 @@ impl StatusPage {
|
||||
once,
|
||||
desc_snippet: None,
|
||||
},
|
||||
refresh_interval,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -965,14 +978,19 @@ impl StatusPage {
|
||||
// We avoid writing while keeping the lock, to reduce
|
||||
// contention.
|
||||
let (status, repos) = {
|
||||
let status = data.status_page_as_html()?.to_string();
|
||||
let status = data.status_page_as_html(self.refresh_interval)?.to_string();
|
||||
|
||||
let mut repos = vec![];
|
||||
for (_, rid) in data.repos() {
|
||||
let basename = rid_to_basename(rid);
|
||||
let filename = dirname.join(format!("{basename}.html"));
|
||||
let alias = data.repo_alias(rid).unwrap_or(nameless.clone());
|
||||
let repopage = data.per_repo_page_as_html(rid, &alias, &data.timestamp);
|
||||
let repopage = data.per_repo_page_as_html(
|
||||
rid,
|
||||
&alias,
|
||||
&data.timestamp,
|
||||
self.refresh_interval,
|
||||
);
|
||||
repos.push((filename, repopage.to_string()));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user