Skip to content

Commit

Permalink
feat(state_update_job): Fix from review
Browse files Browse the repository at this point in the history
  • Loading branch information
akhercha committed Jul 2, 2024
1 parent 95e621d commit 4488774
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
8 changes: 1 addition & 7 deletions crates/orchestrator/src/database/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,7 @@ pub trait Database: Send + Sync {
async fn create_job(&self, job: JobItem) -> Result<JobItem>;
async fn get_job_by_id(&self, id: Uuid) -> Result<Option<JobItem>>;
async fn get_job_by_internal_id_and_type(&self, internal_id: &str, job_type: &JobType) -> Result<Option<JobItem>>;
async fn update_job(
&self,
job: &JobItem,
external_id: String,
new_status: JobStatus,
metadata: HashMap<String, String>,
) -> Result<()>;
async fn update_job(&self, job: &JobItem) -> Result<()>;
async fn update_job_status(&self, job: &JobItem, new_status: JobStatus) -> Result<()>;
async fn update_metadata(&self, job: &JobItem, metadata: HashMap<String, String>) -> Result<()>;
async fn get_latest_job_by_type_and_internal_id(&self, job_type: JobType) -> Result<Option<JobItem>>;
Expand Down
13 changes: 2 additions & 11 deletions crates/orchestrator/src/database/mongodb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,8 @@ impl Database for MongoDb {
Ok(self.get_job_collection().find_one(filter, None).await?)
}

async fn update_job(
&self,
job: &JobItem,
external_id: String,
new_status: JobStatus,
metadata: HashMap<String, String>,
) -> Result<()> {
let mut job_doc = bson::to_document(job)?;
job_doc.insert("external_id", external_id);
job_doc.insert("status", bson::to_bson(&new_status)?);
job_doc.insert("metadata", bson::to_document(&metadata)?);
async fn update_job(&self, job: &JobItem) -> Result<()> {
let job_doc = bson::to_document(job)?;
let update = doc! {
"$set": job_doc
};
Expand Down
6 changes: 5 additions & 1 deletion crates/orchestrator/src/jobs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ pub async fn process_job(id: Uuid) -> Result<()> {
let external_id = job_handler.process_job(config.as_ref(), &mut job).await?;
let metadata = increment_key_in_metadata(&job.metadata, JOB_PROCESS_ATTEMPT_METADATA_KEY)?;

config.database().update_job(&job, external_id.clone(), JobStatus::PendingVerification, metadata).await?;
job.external_id = external_id.into();
job.status = JobStatus::PendingVerification;
job.metadata = metadata;

config.database().update_job(&job).await?;

add_job_to_verification_queue(job.id, Duration::from_secs(job_handler.verification_polling_delay_seconds()))
.await?;
Expand Down

0 comments on commit 4488774

Please sign in to comment.