Skip to content

Commit dd9dc61

Browse files
committed
Add delegation support
1 parent 3ee2454 commit dd9dc61

16 files changed

Lines changed: 1439 additions & 108 deletions

Cargo.lock

Lines changed: 70 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

opsqueue/Cargo.toml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ repository = "https://github.com/channable/opsqueue"
77
license = "MIT"
88

99
[lib]
10-
name="opsqueue"
11-
path="src/lib.rs"
10+
name = "opsqueue"
11+
path = "src/lib.rs"
1212

1313
[[bin]]
14-
name="opsqueue"
15-
path="app/main.rs"
14+
name = "opsqueue"
15+
path = "app/main.rs"
1616
required-features = ["server-logic"]
1717

1818
[dependencies]
@@ -80,6 +80,8 @@ workspace = true
8080

8181
[dev-dependencies]
8282
insta.workspace = true
83+
wiremock = "0.6.5"
84+
tower = "0.5.3"
8385

8486
[features]
8587
# Dependencies only in use by the server-logic:
@@ -92,8 +94,9 @@ server-logic = [
9294
"dep:tower-http",
9395
"dep:axum-prometheus",
9496
"dep:sentry",
95-
"dep:sentry-tracing"
96-
]
97+
"dep:sentry-tracing",
98+
"dep:reqwest",
99+
]
97100
# Dependencies only in use by the client libraries:
98101
client-logic = [
99102
"dep:reqwest",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROP TABLE submissions_external_task;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CREATE TABLE submissions_external_task
2+
(
3+
submission_id BIGINT NOT NULL UNIQUE,
4+
task_id TEXT NOT NULL UNIQUE,
5+
last_status_sent TEXT
6+
);
12 KB
Binary file not shown.

opsqueue/src/common/chunk.rs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -300,18 +300,21 @@ pub mod db {
300300
chunk_id: ChunkId,
301301
output_content: Option<Vec<u8>>,
302302
mut conn: impl WriterConnection,
303-
) -> Result<(), E<DatabaseError, SubmissionNotFound>> {
304-
let chunks_moved = conn
303+
) -> Result<bool, E<DatabaseError, SubmissionNotFound>> {
304+
let (chunks_moved, completed_submission) = conn
305305
.transaction(move |mut tx| {
306306
Box::pin(async move {
307307
let chunks_moved =
308308
complete_chunk_raw(chunk_id, output_content, &mut tx).await?;
309+
310+
let mut completed_submission = false;
309311
if chunks_moved {
310-
crate::common::submission::db::maybe_complete_submission(
311-
chunk_id.submission_id,
312-
&mut tx,
313-
)
314-
.await?;
312+
completed_submission =
313+
crate::common::submission::db::maybe_complete_submission(
314+
chunk_id.submission_id,
315+
&mut tx,
316+
)
317+
.await?;
315318
} else {
316319
tracing::warn!(
317320
"Could not complete chunk {:?} because it was either: \
@@ -320,15 +323,18 @@ pub mod db {
320323
);
321324
}
322325

323-
Result::<bool, E<DatabaseError, SubmissionNotFound>>::Ok(chunks_moved)
326+
Result::<(bool, bool), E<DatabaseError, SubmissionNotFound>>::Ok((
327+
chunks_moved,
328+
completed_submission,
329+
))
324330
})
325331
})
326332
.await?;
327333

328334
if chunks_moved {
329335
counter!(crate::prometheus::CHUNKS_COMPLETED_COUNTER).increment(1);
330336
}
331-
Ok(())
337+
Ok(completed_submission)
332338
}
333339

334340
/// This function MUST be called inside a transaction.
@@ -657,8 +663,8 @@ pub mod db {
657663
submission_id,
658664
submission_id,
659665
)
660-
.execute(conn.get_inner())
661-
.await?;
666+
.execute(conn.get_inner())
667+
.await?;
662668
Ok(())
663669
}
664670

@@ -687,8 +693,8 @@ pub mod db {
687693
submission_id,
688694
submission_id,
689695
)
690-
.execute(conn.get_inner())
691-
.await?;
696+
.execute(conn.get_inner())
697+
.await?;
692698

693699
counter!(crate::prometheus::CHUNKS_SKIPPED_COUNTER).increment(query_res.rows_affected());
694700
Ok(())
@@ -962,10 +968,10 @@ pub mod test {
962968
.expect("insertion failed");
963969

964970
let res = complete_chunk(chunk_id, None, &mut conn).await;
965-
assert_matches!(res, Ok(()));
971+
assert_matches!(res, Ok(false));
966972

967973
let res = complete_chunk(chunk_id, None, &mut conn).await;
968-
assert_matches!(res, Ok(()));
974+
assert_matches!(res, Ok(false));
969975
}
970976

971977
#[sqlx::test(migrator = "crate::MIGRATOR")]

0 commit comments

Comments
 (0)