Skip to content

Commit 54b879f

Browse files
committed
Auto merge of #2066 - jtgeibel:prod/add-more-bg-job-logging, r=smarnach
Add more logging to background jobs r? @smarnach
2 parents 941b460 + b32600e commit 54b879f

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

src/bin/background-worker.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ fn main() {
4141

4242
let repository_config = RepositoryConfig::from_environment();
4343
let repository = Repository::open(&repository_config).expect("Failed to clone index");
44+
println!("Index cloned");
4445

4546
let environment = Environment::new(
4647
repository,

src/bin/enqueue-job.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ use diesel::PgConnection;
55
fn main() -> AppResult<()> {
66
let conn = db::connect_now()?;
77
let mut args = std::env::args().skip(1);
8-
match &*args.next().unwrap_or_default() {
8+
9+
let job = args.next().unwrap_or_default();
10+
println!("Enqueueing background job: {}", job);
11+
12+
match &*job {
913
"update_downloads" => tasks::update_downloads().enqueue(&conn),
1014
"dump_db" => {
1115
let database_url = args.next().unwrap_or_else(|| env("DATABASE_URL"));

src/tasks/dump_db.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,16 @@ pub fn dump_db(
1616
target_name: String,
1717
) -> Result<(), PerformError> {
1818
let directory = DumpDirectory::create()?;
19+
20+
println!("Begin exporting database");
1921
directory.populate(&database_url)?;
22+
23+
println!("Creating tarball");
2024
let tarball = DumpTarball::create(&directory.export_dir)?;
21-
tarball.upload(&target_name, &env.uploader)?;
22-
println!("Database dump uploaded to {}.", &target_name);
25+
26+
println!("Uploading tarball");
27+
let size = tarball.upload(&target_name, &env.uploader)?;
28+
println!("Database dump uploaded {} bytes to {}.", size, &target_name);
2329
Ok(())
2430
}
2531

@@ -145,7 +151,7 @@ impl DumpTarball {
145151
Ok(result)
146152
}
147153

148-
fn upload(&self, target_name: &str, uploader: &Uploader) -> Result<(), PerformError> {
154+
fn upload(&self, target_name: &str, uploader: &Uploader) -> Result<u64, PerformError> {
149155
let client = reqwest::Client::new();
150156
let tarfile = File::open(&self.tarball_path)?;
151157
let content_length = tarfile.metadata()?.len();
@@ -160,7 +166,7 @@ impl DumpTarball {
160166
header::HeaderMap::new(),
161167
)
162168
.map_err(std_error_no_send)?;
163-
Ok(())
169+
Ok(content_length)
164170
}
165171
}
166172

src/tasks/update_downloads.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ fn update(conn: &PgConnection) -> QueryResult<()> {
2323
.filter(processed.eq(false))
2424
.filter(downloads.ne(counted))
2525
.load(conn)?;
26+
27+
println!("Updating {} versions", rows.len());
2628
collect(conn, &rows)?;
29+
println!("Finished updating versions");
2730

2831
// Anything older than 24 hours ago will be frozen and will not be queried
2932
// against again.
@@ -33,17 +36,18 @@ fn update(conn: &PgConnection) -> QueryResult<()> {
3336
.filter(downloads.eq(counted))
3437
.filter(processed.eq(false))
3538
.execute(conn)?;
39+
println!("Finished freezing old version_downloads");
3640

3741
no_arg_sql_function!(refresh_recent_crate_downloads, ());
3842
select(refresh_recent_crate_downloads).execute(conn)?;
43+
println!("Finished running refresh_recent_crate_downloads");
44+
3945
Ok(())
4046
}
4147

4248
fn collect(conn: &PgConnection, rows: &[VersionDownload]) -> QueryResult<()> {
4349
use diesel::update;
4450

45-
println!("updating {} versions", rows.len());
46-
4751
for download in rows {
4852
let amt = download.downloads - download.counted;
4953

0 commit comments

Comments
 (0)