-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create indexer module with common indexing logic shared by bombastic and vexination. * Use infrastructure HTTP endpoint on indexers to trigger reindexing and checking reindexing status. * Create admin module with commands that can be used by system administrators. * Add trust admin reindex command as a way to trigger reindexing and checking reindexing status using the indexer HTTP endpoint. Issue #379, #9
- Loading branch information
Ulf Lilleengen
committed
Aug 14, 2023
1 parent
f6c9525
commit 71cd5ea
Showing
22 changed files
with
551 additions
and
326 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "trustification-admin" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
serde = { version = "1.0", features = ["derive"] } | ||
serde_json = "1.0.68" | ||
tokio = { version = "1.0", features = ["full"] } | ||
log = "0.4" | ||
clap = { version = "4", features = ["derive"] } | ||
anyhow = "1" | ||
reqwest = { version = "0.11.16", features = ["stream"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use std::process::ExitCode; | ||
|
||
mod reindex; | ||
|
||
#[derive(clap::Subcommand, Debug)] | ||
pub enum Command { | ||
#[command(subcommand)] | ||
Reindex(reindex::Reindex), | ||
} | ||
|
||
impl Command { | ||
pub async fn run(self) -> anyhow::Result<ExitCode> { | ||
match self { | ||
Self::Reindex(reindex) => reindex.run().await, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use std::process::ExitCode; | ||
|
||
use reqwest::StatusCode; | ||
|
||
#[derive(clap::Subcommand, Debug)] | ||
pub enum Reindex { | ||
Status(ReindexStatus), | ||
Start(ReindexStart), | ||
} | ||
|
||
impl Reindex { | ||
pub async fn run(self) -> anyhow::Result<ExitCode> { | ||
match self { | ||
Self::Start(run) => run.run().await, | ||
Self::Status(run) => run.run().await, | ||
} | ||
} | ||
} | ||
|
||
#[derive(clap::Args, Debug)] | ||
#[command(about = "Trigger reindex", args_conflicts_with_subcommands = true)] | ||
pub struct ReindexStart { | ||
#[arg(long = "devmode", default_value_t = false)] | ||
pub devmode: bool, | ||
|
||
#[arg(short = 'i', long = "indexer", default_value = "http://localhost:8080/")] | ||
pub indexer_url: String, | ||
} | ||
|
||
impl ReindexStart { | ||
pub async fn run(self) -> anyhow::Result<ExitCode> { | ||
let client = reqwest::Client::new(); | ||
match client.post(self.indexer_url).send().await { | ||
Ok(response) => { | ||
if response.status() == StatusCode::OK { | ||
println!("Reindexing started successfully"); | ||
} else { | ||
let body = response.text().await; | ||
println!("Error starting reindexing: {:?}", body); | ||
} | ||
} | ||
Err(e) => { | ||
println!("Error starting reindexing: {:?}", e); | ||
} | ||
} | ||
|
||
Ok(ExitCode::SUCCESS) | ||
} | ||
} | ||
|
||
#[derive(clap::Args, Debug)] | ||
#[command(about = "Check reindex status", args_conflicts_with_subcommands = true)] | ||
pub struct ReindexStatus { | ||
#[arg(long = "devmode", default_value_t = false)] | ||
pub devmode: bool, | ||
|
||
#[arg(short = 'i', long = "indexer", default_value = "http://localhost:8080/")] | ||
pub indexer_url: String, | ||
} | ||
|
||
impl ReindexStatus { | ||
pub async fn run(self) -> anyhow::Result<ExitCode> { | ||
Ok(ExitCode::SUCCESS) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.