Radish alpha
r
rad:zwTxygwuz5LDGBq255RA2CbNGrz8
Radicle CI broker
Radicle
Git
feat: add cibtool remove event option --all to empty event queue
Merged liw opened 1 year ago

Signed-off-by: Lars Wirzenius liw@liw.fi

3 files changed +45 -6 32825106 caf839b5
modified ci-broker.md
@@ -922,6 +922,37 @@ when I run cibtool --db x.db event list
then stdout is exactly ""
~~~

+
## Can remove all queued events
+

+
_Want:_ `cibtool` can remove all queued events in one operation.
+

+
_Why:_ This will be useful if the CI broker changes how CI events or
+
their serialization in an incompatible way, again, or when the node
+
operator wants to prevent many CI runs from happening.
+

+
_Who:_ `cib-devs`, `node-ops`
+

+
~~~scenario
+
given file radenv.sh
+
given file setup-node.sh
+
when I run bash radenv.sh bash setup-node.sh
+

+
given an installed cibtool
+
when I run cibtool --db x.db event list
+
then stdout is exactly ""
+

+
when I run bash radenv.sh cibtool --db x.db event add --repo testy --ref main --commit HEAD --base HEAD
+
when I run bash radenv.sh cibtool --db x.db event add --repo testy --ref main --commit HEAD --base HEAD
+
when I run bash radenv.sh cibtool --db x.db event add --repo testy --ref main --commit HEAD --base HEAD
+
when I run bash radenv.sh cibtool --db x.db event add --repo testy --ref main --commit HEAD --base HEAD
+
when I run bash radenv.sh cibtool --db x.db event add --repo testy --ref main --commit HEAD --base HEAD
+
when I run bash radenv.sh cibtool --db x.db event add --repo testy --ref main --commit HEAD --base HEAD
+

+
when I run cibtool --db x.db event remove --all
+
when I run cibtool --db x.db event list
+
then stdout is exactly ""
+
~~~
+

## Can add shutdown event to queue

_Want:_ `cibtool` can add a shutdown event to the queued
modified src/bin/cibtool.rs
@@ -301,7 +301,7 @@ enum CibToolError {
    #[error("failed to write event ID to file {0}")]
    WriteEventId(PathBuf, #[source] std::io::Error),

-
    #[error("one of --id or --id-file is required")]
+
    #[error("one of --id or --id-file or --all is required")]
    MissingId,

    #[error("programming error: confused about state and result of run")]
modified src/bin/cibtoolcmd/event.rs
@@ -255,9 +255,13 @@ impl Leaf for ShowEvent {
#[derive(Parser)]
pub struct RemoveEvent {
    /// ID of event to remove.
-
    #[clap(long, required_unless_present = "id_file")]
+
    #[clap(long)]
    id: Option<QueueId>,

+
    /// Remove all queued events.
+
    #[clap(long)]
+
    all: bool,
+

    /// Read ID of event to remove from this file.
    #[clap(long)]
    id_file: Option<PathBuf>,
@@ -267,17 +271,21 @@ impl Leaf for RemoveEvent {
    fn run(&self, args: &Args) -> Result<(), CibToolError> {
        let db = args.open_db()?;

-
        let id = if let Some(id) = &self.id {
-
            id.clone()
+
        let ids = if let Some(id) = &self.id {
+
            vec![id.clone()]
        } else if let Some(filename) = &self.id_file {
            let id = read(filename).map_err(|e| CibToolError::ReadEventId(filename.into(), e))?;
            let id = String::from_utf8_lossy(&id).to_string();
-
            QueueId::from(&id)
+
            vec![QueueId::from(&id)]
+
        } else if self.all {
+
            db.queued_ci_events()?
        } else {
            return Err(CibToolError::MissingId);
        };

-
        db.remove_queued_ci_event(&id)?;
+
        for id in ids {
+
            db.remove_queued_ci_event(&id)?;
+
        }
        Ok(())
    }
}