Skip to content

Commit

Permalink
feat: rewrite worker to use http api
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Mar 11, 2024
1 parent 3af8c05 commit 18e5932
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 861 deletions.
670 changes: 12 additions & 658 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ edition = "2021"
[dependencies]
anyhow = "1.0.80"
chrono = { version = "0.4.34", features = ["serde"] }
lapin = "2.3.1"
serde = { version = "1.0.196", features = ["derive"] }
12 changes: 3 additions & 9 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
use lapin::{
options::QueueDeclareOptions,
types::{AMQPValue, FieldTable},
Channel, Queue,
};
use serde::{Deserialize, Serialize};
use std::time::Duration;

#[derive(Serialize, Deserialize)]
pub struct WorkerPollRequest {
pub hostname: String,
pub arch: String,
}

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
pub struct WorkerPollResponse {
pub job_id: i32,
pub git_branch: String,
Expand Down Expand Up @@ -53,10 +47,10 @@ pub struct JobOk {
pub pushpkg_success: bool,
}

#[derive(Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
pub struct WorkerJobUpdateRequest {
pub hostname: String,
pub arch: String,
pub job_id: i32,
pub result: JobResult,
}
}
2 changes: 1 addition & 1 deletion server/src/api.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::collections::BTreeMap;
use crate::{
github::get_packages_from_pr,
job::get_crab_github_installation,
Expand All @@ -10,6 +9,7 @@ use anyhow::Context;
use buildit_utils::github::{get_archs, update_abbs};
use diesel::{dsl::count, ExpressionMethods, QueryDsl, RunQueryDsl, SelectableHelper};
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
use tracing::warn;

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down
4 changes: 2 additions & 2 deletions server/src/bot.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::{
api::{pipeline_new, pipeline_new_pr, pipeline_status, worker_status, JobSource},
formatter::{code_repr_string, to_html_new_job_summary},
formatter::to_html_new_job_summary,
github::{get_github_token, login_github},
DbPool, ALL_ARCH, ARGS,
};
use buildit_utils::github::{get_archs, OpenPRError, OpenPRRequest};
use chrono::Local;
use serde_json::Value;

use std::borrow::Cow;
use teloxide::{
prelude::*,
Expand Down
13 changes: 1 addition & 12 deletions server/src/github_webhooks.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
use crate::{
formatter::to_html_new_job_summary,
github::get_packages_from_pr,
ARGS,
};
use anyhow::{anyhow, bail};
use buildit_utils::github::{get_archs, update_abbs};
use futures::StreamExt;
use octocrab::Octocrab;
use reqwest::StatusCode;
use serde::Deserialize;
use std::{path::Path, time::Duration};

#[derive(Debug, Deserialize)]
struct WebhookComment {
Expand Down Expand Up @@ -296,4 +285,4 @@ async fn is_org_user(user: &str) -> anyhow::Result<bool> {
}
}
*/
*/
21 changes: 5 additions & 16 deletions server/src/job.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
use crate::{
formatter::{to_html_build_result, to_markdown_build_result, FAILED, SUCCESS},
DbPool, ARGS,
};
use crate::ARGS;

use buildit_utils::LOONGARCH64;
use buildit_utils::{AMD64, ARM64, LOONGSON3, MIPS64R6EL, NOARCH, PPC64EL, RISCV64};
use futures::StreamExt;
use octocrab::params::checks::CheckRunConclusion;
use octocrab::params::checks::CheckRunOutput;
use octocrab::{
models::{CheckRunId, InstallationId},
Octocrab,
};
use std::time::Duration;
use teloxide::{prelude::*, types::ParseMode};
use octocrab::{models::InstallationId, Octocrab};

use teloxide::prelude::*;

Check warning on line 5 in server/src/job.rs

View workflow job for this annotation

GitHub Actions / build

unused import: `teloxide::prelude`

/// Create octocrab instance authenticated as github installation
pub async fn get_crab_github_installation() -> anyhow::Result<Option<Octocrab>> {
Expand All @@ -39,4 +28,4 @@ pub async fn get_crab_github_installation() -> anyhow::Result<Option<Octocrab>>
}
}
return Ok(None);
}
}
7 changes: 1 addition & 6 deletions server/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
use chrono::{DateTime, Local};
use clap::Parser;
use diesel::{
r2d2::{ConnectionManager, Pool},
PgConnection,
};
use once_cell::sync::Lazy;
use std::{
collections::BTreeMap,
path::PathBuf,
sync::{Arc, Mutex},
};
use std::path::PathBuf;

pub mod api;
pub mod bot;
Expand Down
7 changes: 2 additions & 5 deletions server/src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,15 @@ use axum::{
response::{IntoResponse, Response},
};
use buildit_utils::LOONGARCH64;
use buildit_utils::{AMD64, ARM64, LOONGSON3, MIPS64R6EL, NOARCH, PPC64EL, RISCV64};
use buildit_utils::{AMD64, ARM64, LOONGSON3, MIPS64R6EL, PPC64EL, RISCV64};
use common::{
JobOk, JobResult, WorkerHeartbeatRequest, WorkerJobUpdateRequest, WorkerPollRequest,
WorkerPollResponse,
};
use diesel::{Connection, ExpressionMethods, OptionalExtension, QueryDsl, RunQueryDsl};
use octocrab::models::CheckRunId;
use octocrab::params::checks::CheckRunConclusion;
use octocrab::params::checks::CheckRunOutput;
use octocrab::{
models::{CheckRunId, InstallationId},
Octocrab,
};
use serde::{Deserialize, Serialize};
use teloxide::types::ChatId;
use teloxide::{prelude::*, types::ParseMode};
Expand Down
1 change: 0 additions & 1 deletion worker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ dotenv = "0.15.0"
env_logger = "0.11.2"
futures = "0.3.30"
gethostname = "0.4.3"
lapin = "2.3.1"
log = "0.4.20"
num_cpus = "1.16.0"
once_cell = "1.19.0"
Expand Down
Loading

0 comments on commit 18e5932

Please sign in to comment.