Add Created status to JobStatus enum and store_job_in_redis_with_status method
This commit is contained in:
@@ -204,8 +204,8 @@ impl Client {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Store this job in Redis
|
||||
pub async fn store_job_in_redis(&self, job: &Job) -> Result<(), JobError> {
|
||||
/// Store this job in Redis with the specified status
|
||||
pub async fn store_job_in_redis_with_status(&self, job: &Job, status: JobStatus) -> Result<(), JobError> {
|
||||
let mut conn = self.redis_client
|
||||
.get_multiplexed_async_connection()
|
||||
.await
|
||||
@@ -220,7 +220,7 @@ impl Client {
|
||||
// Store job data in Redis hash
|
||||
let _: () = conn.hset_multiple(&job_key, &[
|
||||
("data", job_data),
|
||||
("status", JobStatus::Dispatched.as_str().to_string()),
|
||||
("status", status.as_str().to_string()),
|
||||
("created_at", job.created_at.to_rfc3339()),
|
||||
("updated_at", job.updated_at.to_rfc3339()),
|
||||
]).await
|
||||
@@ -232,6 +232,11 @@ impl Client {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Store this job in Redis (defaults to Dispatched status for backwards compatibility)
|
||||
pub async fn store_job_in_redis(&self, job: &Job) -> Result<(), JobError> {
|
||||
self.store_job_in_redis_with_status(job, JobStatus::Dispatched).await
|
||||
}
|
||||
|
||||
/// Load a job from Redis by ID
|
||||
pub async fn load_job_from_redis(
|
||||
|
||||
18
src/job.rs
18
src/job.rs
@@ -19,6 +19,7 @@ pub struct JobSignature {
|
||||
/// Job status enumeration
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub enum JobStatus {
|
||||
Created,
|
||||
Dispatched,
|
||||
WaitingForPrerequisites,
|
||||
Started,
|
||||
@@ -30,6 +31,7 @@ pub enum JobStatus {
|
||||
impl JobStatus {
|
||||
pub fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
JobStatus::Created => "created",
|
||||
JobStatus::Dispatched => "dispatched",
|
||||
JobStatus::WaitingForPrerequisites => "waiting_for_prerequisites",
|
||||
JobStatus::Started => "started",
|
||||
@@ -41,6 +43,7 @@ impl JobStatus {
|
||||
|
||||
pub fn from_str(s: &str) -> Option<Self> {
|
||||
match s {
|
||||
"created" => Some(JobStatus::Created),
|
||||
"dispatched" => Some(JobStatus::Dispatched),
|
||||
"waiting_for_prerequisites" => Some(JobStatus::WaitingForPrerequisites),
|
||||
"started" => Some(JobStatus::Started),
|
||||
@@ -150,15 +153,11 @@ impl Job {
|
||||
|
||||
/// Verify that all signatures are valid
|
||||
/// Returns Ok(()) if verification passes, Err otherwise
|
||||
#[cfg(feature = "crypto")]
|
||||
/// Empty signatures list is allowed - loop simply won't execute
|
||||
pub fn verify_signatures(&self) -> Result<(), JobError> {
|
||||
use secp256k1::{Message, PublicKey, Secp256k1, ecdsa::Signature};
|
||||
use sha2::{Sha256, Digest};
|
||||
|
||||
if self.signatures.is_empty() {
|
||||
return Err(JobError::Unauthorized("No signatures provided".to_string()));
|
||||
}
|
||||
|
||||
// Get the canonical representation and hash it
|
||||
let canonical = self.canonical_representation();
|
||||
let mut hasher = Sha256::new();
|
||||
@@ -169,7 +168,7 @@ impl Job {
|
||||
let message = Message::from_digest_slice(&hash)
|
||||
.map_err(|e| JobError::SignatureVerificationFailed(format!("Invalid message: {}", e)))?;
|
||||
|
||||
// Verify each signature
|
||||
// Verify each signature (if any)
|
||||
for sig_data in &self.signatures {
|
||||
// Decode public key
|
||||
let pubkey_bytes = hex::decode(&sig_data.public_key)
|
||||
@@ -190,13 +189,6 @@ impl Job {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Verify signatures (no-op when crypto feature is disabled)
|
||||
#[cfg(not(feature = "crypto"))]
|
||||
pub fn verify_signatures(&self) -> Result<(), JobError> {
|
||||
log::warn!("Signature verification disabled - crypto feature not enabled");
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Builder for constructing job execution requests.
|
||||
|
||||
@@ -149,7 +149,7 @@ async fn wait_for_job_completion(
|
||||
JobStatus::Finished | JobStatus::Error => {
|
||||
return Ok(status);
|
||||
}
|
||||
JobStatus::Dispatched | JobStatus::WaitingForPrerequisites | JobStatus::Started => {
|
||||
JobStatus::Created | JobStatus::Dispatched | JobStatus::WaitingForPrerequisites | JobStatus::Started => {
|
||||
// Continue polling
|
||||
tokio::time::sleep(poll_interval).await;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user