Skip to content

Commit

Permalink
finish job runner
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed Nov 26, 2023
1 parent 763faa7 commit 8088217
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 33 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 0 additions & 30 deletions crates/kitsune-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,36 +107,6 @@ fn prepare_captcha(config: &captcha::Configuration) -> AnyCaptcha {
}
}
fn prepare_storage(config: &Configuration) -> eyre::Result<AnyStorageBackend> {
let storage = match config.storage {
storage::Configuration::Fs(ref fs_config) => {
FsStorage::new(fs_config.upload_dir.as_str().into()).into()
}
storage::Configuration::S3(ref s3_config) => {
let path_style = if s3_config.force_path_style {
rusty_s3::UrlStyle::Path
} else {
rusty_s3::UrlStyle::VirtualHost
};
let s3_credentials = S3Credentials::new(
s3_config.access_key.as_str(),
s3_config.secret_access_key.as_str(),
);
let s3_bucket = S3Bucket::new(
s3_config.endpoint_url.parse()?,
path_style,
s3_config.bucket_name.to_string(),
s3_config.region.to_string(),
)?;
S3Storage::new(s3_bucket, s3_credentials).into()
}
};
Ok(storage)
}
fn prepare_mail_sender(
config: &email::Configuration,
) -> eyre::Result<MailSender<AsyncSmtpTransport<Tokio1Executor>>> {
Expand Down
4 changes: 3 additions & 1 deletion crates/kitsune-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ bytes = "1.5.0"
derive_builder = "0.12.0"
diesel = "2.1.4"
diesel-async = "0.4.1"
eyre = "0.6.9"
futures-util = "0.3.29"
garde = { version = "0.16.2", default-features = false, features = [
"derive",
Expand All @@ -26,6 +27,7 @@ iso8601-timestamp = "0.2.12"
kitsune-blocking = { path = "../kitsune-blocking" }
kitsune-cache = { path = "../kitsune-cache" }
kitsune-captcha = { path = "../kitsune-captcha" }
kitsune-config = { path = "../kitsune-config" }
kitsune-consts = { path = "../kitsune-consts" }
kitsune-core = { path = "../kitsune-core" }
kitsune-db = { path = "../kitsune-db" }
Expand All @@ -45,6 +47,7 @@ pkcs8 = "0.10.2"
post-process = { path = "../../lib/post-process" }
rand = "0.8.5"
rsa = "0.9.4"
rusty-s3 = { version = "0.5.0", default-features = false }
scoped-futures = "0.1.3"
simd-json = "0.13.4"
smol_str = "0.2.0"
Expand All @@ -60,7 +63,6 @@ zxcvbn = { version = "2.2.2", default-features = false }
meilisearch = ["kitsune-search/meilisearch"]

[dev-dependencies]
eyre = "0.6.9"
hex-simd = { version = "0.8.0", features = ["unstable"] }
hyper = "0.14.27"
kitsune-activitypub = { path = "../kitsune-activitypub" }
Expand Down
1 change: 1 addition & 0 deletions crates/kitsune-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub mod job;
pub mod mailing;
pub mod notification;
pub mod post;
pub mod prepare;
pub mod search;
pub mod timeline;
pub mod url;
Expand Down
32 changes: 32 additions & 0 deletions crates/kitsune-service/src/prepare.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use kitsune_config::storage;
use kitsune_storage::{fs::Storage as FsStorage, s3::Storage as S3Storage, AnyStorageBackend};

pub fn storage(config: &storage::Configuration) -> eyre::Result<AnyStorageBackend> {
let storage = match config {
storage::Configuration::Fs(ref fs_config) => {
FsStorage::new(fs_config.upload_dir.as_str().into()).into()
}
storage::Configuration::S3(ref s3_config) => {
let path_style = if s3_config.force_path_style {
rusty_s3::UrlStyle::Path
} else {
rusty_s3::UrlStyle::VirtualHost
};

let s3_credentials = rusty_s3::Credentials::new(
s3_config.access_key.as_str(),
s3_config.secret_access_key.as_str(),
);
let s3_bucket = rusty_s3::Bucket::new(
s3_config.endpoint_url.parse()?,
path_style,
s3_config.bucket_name.to_string(),
s3_config.region.to_string(),
)?;

S3Storage::new(s3_bucket, s3_credentials).into()
}
};

Ok(storage)
}
17 changes: 15 additions & 2 deletions kitsune-job-runner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use kitsune_config::Configuration;
use kitsune_consts::VERSION;
use kitsune_federation_filter::FederationFilter;
use kitsune_job_runner::JobDispatcherState;
use kitsune_service::{attachment::AttachmentService, url::UrlService};
use std::path::PathBuf;
use tokio::fs;

Expand Down Expand Up @@ -36,12 +37,24 @@ async fn main() -> eyre::Result<()> {
.await?;
let job_queue = kitsune_job_runner::prepare_job_queue(db_pool.clone(), &config.job_queue)?;

let url_service = UrlService::builder()
.domain(config.url.domain)
.scheme(config.url.scheme)
.webfinger_domain(config.instance.webfinger_domain)
.build();
let attachment_service = AttachmentService::builder()
.db_pool(db_pool.clone())
.media_proxy_enabled(config.server.media_proxy_enabled)
.storage_backend(kitsune_service::prepare::storage(&config.storage)?)
.url_service(url_service.clone())
.build();
let federation_filter = FederationFilter::new(&config.instance.federation_filter)?;

let state = JobDispatcherState::builder()
.attachment_service()
.attachment_service(attachment_service)
.db_pool(db_pool)
.federation_filter(federation_filter)
.url_service()
.url_service(url_service)
.build();

kitsune_job_runner::run_dispatcher(job_queue, state, config.job_queue.num_workers.into()).await;
Expand Down

0 comments on commit 8088217

Please sign in to comment.