Skip to content

Commit 5dc833c

Browse files
committed
dump_db: Extract Archives struct
1 parent c08b381 commit 5dc833c

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

src/worker/jobs/dump_db.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl BackgroundJob for DumpDb {
3434

3535
let database_url = self.database_url.clone();
3636

37-
let (tarball, zip) = spawn_blocking(move || {
37+
let archives = spawn_blocking(move || {
3838
let directory = DumpDirectory::create()?;
3939

4040
info!("Exporting database…");
@@ -49,7 +49,9 @@ impl BackgroundJob for DumpDb {
4949
.await?;
5050

5151
info!("Uploading tarball…");
52-
env.storage.upload_db_dump(TAR_PATH, tarball.path()).await?;
52+
env.storage
53+
.upload_db_dump(TAR_PATH, archives.tar.path())
54+
.await?;
5355
info!("Database dump tarball uploaded");
5456

5557
info!("Invalidating CDN caches…");
@@ -66,7 +68,9 @@ impl BackgroundJob for DumpDb {
6668
}
6769

6870
info!("Uploading zip file…");
69-
env.storage.upload_db_dump(ZIP_PATH, zip.path()).await?;
71+
env.storage
72+
.upload_db_dump(ZIP_PATH, archives.zip.path())
73+
.await?;
7074
info!("Database dump zip file uploaded");
7175

7276
info!("Invalidating CDN caches…");
@@ -221,10 +225,12 @@ pub fn run_psql(script: &Path, database_url: &str) -> anyhow::Result<()> {
221225
Ok(())
222226
}
223227

224-
fn create_archives(
225-
export_dir: &Path,
226-
tarball_prefix: &Path,
227-
) -> anyhow::Result<(tempfile::NamedTempFile, tempfile::NamedTempFile)> {
228+
struct Archives {
229+
tar: tempfile::NamedTempFile,
230+
zip: tempfile::NamedTempFile,
231+
}
232+
233+
fn create_archives(export_dir: &Path, tarball_prefix: &Path) -> anyhow::Result<Archives> {
228234
debug!("Creating tarball file…");
229235
let tar_tempfile = tempfile::NamedTempFile::new()?;
230236
let encoder =
@@ -293,7 +299,10 @@ fn create_archives(
293299
drop(tar);
294300
zip.finish()?;
295301

296-
Ok((tar_tempfile, zip_tempfile))
302+
Ok(Archives {
303+
tar: tar_tempfile,
304+
zip: zip_tempfile,
305+
})
297306
}
298307

299308
mod configuration;
@@ -321,8 +330,8 @@ mod tests {
321330
fs::write(p.join("data").join("crate_owners.csv"), "").unwrap();
322331
fs::write(p.join("data").join("users.csv"), "").unwrap();
323332

324-
let (tarball, zip) = create_archives(p, &PathBuf::from("0000-00-00")).unwrap();
325-
let gz = GzDecoder::new(File::open(tarball.path()).unwrap());
333+
let archives = create_archives(p, &PathBuf::from("0000-00-00")).unwrap();
334+
let gz = GzDecoder::new(File::open(archives.tar.path()).unwrap());
326335
let mut tar = Archive::new(gz);
327336

328337
let entries = tar.entries().unwrap();
@@ -341,7 +350,7 @@ mod tests {
341350
]
342351
"###);
343352

344-
let file = File::open(zip.path()).unwrap();
353+
let file = File::open(archives.zip.path()).unwrap();
345354
let reader = BufReader::new(file);
346355

347356
let archive = zip::ZipArchive::new(reader).unwrap();

0 commit comments

Comments
 (0)