feat(worker): V1-2.3 sandboxed verify child and sheet-verify job mode
This commit is contained in:
1 parent
345dde59e6
commit
31fbb0317f
24 files changed
+2145
-87
No files matched your search
@@ -1,6 +1,6 @@
|
||||
//! What the parent needs from Supabase (STORAGE.md §2.2 RPCs and §3.3 Storage calls),
|
||||
//! behind one trait so the job and sweep logic is tested on an in-memory fake and the HTTP
|
||||
//! implementation stays thin.
|
||||
//! What the parent needs from Supabase (STORAGE.md §2.2 RPCs and §3.3 Storage calls), behind
|
||||
//! one trait so the job and sweep logic is tested on an in-memory fake and the HTTP
|
||||
//! implementation stays thin. The M6 verification RPCs (V1-2.3) have a trait of their own.
|
||||
|
||||
use std::fmt;
|
||||
|
||||
@@ -105,3 +105,86 @@ pub trait Backend {
|
||||
) -> BackendResult<Vec<Leftover>>;
|
||||
fn expire_pending_uploads(&self, max_age_seconds: u64) -> BackendResult<i64>;
|
||||
}
|
||||
|
||||
/// One claimed round (`claim_sheet_verifications`, M6).
|
||||
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
|
||||
pub struct VerifyJob {
|
||||
pub review_id: String,
|
||||
pub version_id: String,
|
||||
pub sheet_id: String,
|
||||
pub revision: u32,
|
||||
pub lease_token: String,
|
||||
pub attempts: i64,
|
||||
}
|
||||
|
||||
/// One drawing row of a round's input: registered for the sheet, referenced by the document.
|
||||
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
|
||||
pub struct DrawingRow {
|
||||
pub asset_id: String,
|
||||
pub sha256: String,
|
||||
pub byte_size: u64,
|
||||
pub bucket: String,
|
||||
pub object_key: String,
|
||||
pub uploaded: bool,
|
||||
}
|
||||
|
||||
/// The input of a leased round (`get_sheet_verification_input`): the texts are passed to
|
||||
/// the child as they are, never parsed by the parent.
|
||||
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
|
||||
pub struct VerifyInput {
|
||||
pub review_id: String,
|
||||
pub version_id: String,
|
||||
pub sheet_id: String,
|
||||
pub revision: u32,
|
||||
pub document: String,
|
||||
pub base_document: Option<String>,
|
||||
pub drawings: Vec<DrawingRow>,
|
||||
}
|
||||
|
||||
/// `complete_sheet_verification`: `stale` and `malformed` wrote nothing.
|
||||
#[derive(Debug, Clone, Copy, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum CompleteAnswer {
|
||||
Passed,
|
||||
Failed,
|
||||
Stale,
|
||||
Malformed,
|
||||
}
|
||||
|
||||
/// `fail_sheet_verification`: claimable again, closed `unavailable` at the attempt limit,
|
||||
/// or `stale` (nothing written).
|
||||
#[derive(Debug, Clone, Copy, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum FailAnswer {
|
||||
Retry,
|
||||
Unavailable,
|
||||
Stale,
|
||||
}
|
||||
|
||||
/// The four RPCs of M6 and the drawing download (V1-2.3, `run --jobs sheet-verify`).
|
||||
pub trait VerifyBackend {
|
||||
fn claim_verifications(&self, max_jobs: u32) -> BackendResult<Vec<VerifyJob>>;
|
||||
/// `None` when the lease or the round is stale.
|
||||
fn verification_input(
|
||||
&self,
|
||||
review_id: &str,
|
||||
lease_token: &str,
|
||||
) -> BackendResult<Option<VerifyInput>>;
|
||||
/// `Status(404)` when the object is missing; `Overflow` past `max_bytes`.
|
||||
fn download_drawing(&self, bucket: &str, key: &str, max_bytes: usize)
|
||||
-> BackendResult<Vec<u8>>;
|
||||
/// `verdict` is the child's output, a JSON object.
|
||||
fn complete_verification(
|
||||
&self,
|
||||
review_id: &str,
|
||||
lease_token: &str,
|
||||
verdict: &[u8],
|
||||
) -> BackendResult<CompleteAnswer>;
|
||||
/// `code` is one of the closed worker codes (`verify_job::codes`).
|
||||
fn fail_verification(
|
||||
&self,
|
||||
review_id: &str,
|
||||
lease_token: &str,
|
||||
code: &str,
|
||||
) -> BackendResult<FailAnswer>;
|
||||
}
|
||||
Reference in new issue
Block a user