Skip to content

Commit

Permalink
workers/jobs/dump_db: Remove unnecessary target_name field (#8719)
Browse files Browse the repository at this point in the history
We haven't used this in years and it makes it a bit more complicated to support other file types in the future.
  • Loading branch information
Turbo87 authored May 24, 2024
1 parent 35bdb1a commit ae793df
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
9 changes: 2 additions & 7 deletions src/admin/enqueue_job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ pub enum Command {
DumpDb {
#[arg(env = "READ_ONLY_REPLICA_URL")]
database_url: SecretString,
#[arg(default_value = "db-dump.tar.gz")]
target_name: String,
},
DailyDbMaintenance,
SquashIndex,
Expand Down Expand Up @@ -76,11 +74,8 @@ pub fn run(command: Command) -> Result<()> {
Command::CleanProcessedLogFiles => {
jobs::CleanProcessedLogFiles.enqueue(conn)?;
}
Command::DumpDb {
database_url,
target_name,
} => {
jobs::DumpDb::new(database_url.expose_secret(), target_name).enqueue(conn)?;
Command::DumpDb { database_url } => {
jobs::DumpDb::new(database_url.expose_secret()).enqueue(conn)?;
}
Command::SyncAdmins { force } => {
if !force {
Expand Down
11 changes: 5 additions & 6 deletions src/worker/jobs/dump_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ use std::sync::Arc;
#[derive(Clone, Serialize, Deserialize)]
pub struct DumpDb {
database_url: String,
target_name: String,
}

impl DumpDb {
pub fn new(database_url: impl Into<String>, target_name: impl Into<String>) -> Self {
pub fn new(database_url: impl Into<String>) -> Self {
Self {
database_url: database_url.into(),
target_name: target_name.into(),
}
}
}
Expand All @@ -31,6 +29,7 @@ impl BackgroundJob for DumpDb {
/// Create CSV dumps of the public information in the database, wrap them in a
/// tarball and upload to S3.
async fn run(&self, env: Self::Context) -> anyhow::Result<()> {
let target_name = "db-dump.tar.gz";
let database_url = self.database_url.clone();

let tarball = spawn_blocking(move || {
Expand All @@ -46,19 +45,19 @@ impl BackgroundJob for DumpDb {

info!("Uploading tarball");
Storage::from_environment()
.upload_db_dump(&self.target_name, &tarball.tarball_path)
.upload_db_dump(target_name, &tarball.tarball_path)
.await?;
info!("Database dump tarball uploaded");

info!("Invalidating CDN caches");
if let Some(cloudfront) = env.cloudfront() {
if let Err(error) = cloudfront.invalidate(&self.target_name).await {
if let Err(error) = cloudfront.invalidate(target_name).await {
warn!("failed to invalidate CloudFront cache: {}", error);
}
}

if let Some(fastly) = env.fastly() {
if let Err(error) = fastly.invalidate(&self.target_name).await {
if let Err(error) = fastly.invalidate(target_name).await {
warn!("failed to invalidate Fastly cache: {}", error);
}
}
Expand Down

0 comments on commit ae793df

Please sign in to comment.