Skip to content

Commit 4569fec

Browse files
committed
worker/jobs/downloads: Extract inner run() fn
1 parent 4b31fa9 commit 4569fec

File tree

1 file changed

+30
-26
lines changed

1 file changed

+30
-26
lines changed

src/worker/jobs/downloads.rs

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,36 @@ impl BackgroundJob for ProcessCdnLog {
4040
.build_store(&ctx.config.cdn_log_storage)
4141
.context("Failed to build object store")?;
4242

43+
self.run(store).await
44+
}
45+
}
46+
47+
impl ProcessCdnLog {
48+
fn build_store(&self, config: &CdnLogStorageConfig) -> anyhow::Result<Box<dyn ObjectStore>> {
49+
match config {
50+
CdnLogStorageConfig::S3 {
51+
access_key,
52+
secret_key,
53+
} => {
54+
use secrecy::ExposeSecret;
55+
56+
let store = AmazonS3Builder::new()
57+
.with_region(&self.region)
58+
.with_bucket_name(&self.bucket)
59+
.with_access_key_id(access_key)
60+
.with_secret_access_key(secret_key.expose_secret())
61+
.build()?;
62+
63+
Ok(Box::new(store))
64+
}
65+
CdnLogStorageConfig::Local { path } => {
66+
Ok(Box::new(LocalFileSystem::new_with_prefix(path)?))
67+
}
68+
CdnLogStorageConfig::Memory => Ok(Box::new(InMemory::new())),
69+
}
70+
}
71+
72+
async fn run(&self, store: Box<dyn ObjectStore>) -> anyhow::Result<()> {
4373
let path = object_store::path::Path::parse(&self.path)
4474
.with_context(|| format!("Failed to parse path: {:?}", self.path))?;
4575

@@ -99,29 +129,3 @@ impl BackgroundJob for ProcessCdnLog {
99129
Ok(())
100130
}
101131
}
102-
103-
impl ProcessCdnLog {
104-
fn build_store(&self, config: &CdnLogStorageConfig) -> anyhow::Result<Box<dyn ObjectStore>> {
105-
match config {
106-
CdnLogStorageConfig::S3 {
107-
access_key,
108-
secret_key,
109-
} => {
110-
use secrecy::ExposeSecret;
111-
112-
let store = AmazonS3Builder::new()
113-
.with_region(&self.region)
114-
.with_bucket_name(&self.bucket)
115-
.with_access_key_id(access_key)
116-
.with_secret_access_key(secret_key.expose_secret())
117-
.build()?;
118-
119-
Ok(Box::new(store))
120-
}
121-
CdnLogStorageConfig::Local { path } => {
122-
Ok(Box::new(LocalFileSystem::new_with_prefix(path)?))
123-
}
124-
CdnLogStorageConfig::Memory => Ok(Box::new(InMemory::new())),
125-
}
126-
}
127-
}

0 commit comments

Comments
 (0)