adapt to new trigger message structure in broker

This commit is contained in:
Lars Wirzenius
2024-02-02 15:58:55 +02:00
parent 3a7c8b668d
commit 1bb93c51b2
2 changed files with 674 additions and 54 deletions
Generated
+662 -53
View File
File diff suppressed because it is too large Load Diff
+12 -1
View File
@@ -33,6 +33,7 @@ impl Engine {
/// not existing. The caller should handle the error in some
/// suitable way, such as report that to its stderr, and exit
/// non-zero.
#[allow(clippy::result_large_err)]
pub fn new() -> Result<Self, EngineError> {
// Get config, open admin log for writing. If either of these
// fails, we can't write about the problem to the admin log,
@@ -53,6 +54,7 @@ impl Engine {
/// from stdin, write responses to stdout. Update node admin log
/// with any problems that aren't inherent in the git repository
/// (those go into the run log).
#[allow(clippy::result_large_err)]
pub fn run(&mut self) -> Result<bool, EngineError> {
let req = match self.setup() {
Ok(req) => req,
@@ -65,7 +67,10 @@ impl Engine {
// Check that we got the right kind of request.
let mut success = false;
match req {
Request::Trigger { repo, commit } => {
Request::Trigger { .. } => {
let repo = req.repo();
let commit = req.commit();
self.run_info_builder.repo(repo);
self.run_info_builder.commit(commit);
match self.run_helper(repo, commit) {
@@ -100,6 +105,7 @@ impl Engine {
// Set up CI to run. If something goes wrong, return the error,
// and assume the caller logs it to the admin log.
#[allow(clippy::result_large_err)]
fn setup(&mut self) -> Result<Request, EngineError> {
// Write something to the admin log to indicate we start.
self.adminlog.writeln("Native CI run starts")?;
@@ -113,6 +119,7 @@ impl Engine {
// Finish up after a CI run. If something goes wrong, return the
// error, and assume the caller logs it to the admin log.
#[allow(clippy::result_large_err)]
fn finish(&mut self) -> Result<(), EngineError> {
// Write response message indicating the run has finished.
let ri = self.run_info_builder.build()?;
@@ -140,6 +147,7 @@ impl Engine {
// Execute the CI run. Log any problems to a log for this run, and
// persist that. Update the run info builder as needed.
#[allow(clippy::result_large_err)]
fn run_helper(&mut self, rid: RepoId, commit: Oid) -> Result<bool, EngineError> {
// Pick a run id and create a directory for files related to
// the run.
@@ -185,12 +193,14 @@ impl Engine {
/// Report results to caller (via stdout) and to users (via report
/// on web page).
#[allow(clippy::result_large_err)]
pub fn report(&mut self) -> Result<(), EngineError> {
Ok(())
}
}
/// Create a per-run directory.
#[allow(clippy::result_large_err)]
fn mkdir_run(config: &Config) -> Result<(Uuid, PathBuf), EngineError> {
let state = &config.state;
if !state.exists() {
@@ -204,6 +214,7 @@ fn mkdir_run(config: &Config) -> Result<(Uuid, PathBuf), EngineError> {
}
#[derive(Debug, thiserror::Error)]
#[allow(clippy::large_enum_variant)]
pub enum EngineError {
#[error("failed to create per-run parent directory {0}")]
CreateState(PathBuf, #[source] std::io::Error),