Skip to content

Commit f980327

Browse files
authored
Merge pull request #131 from infraweave-io/fix/add-job-id-verification-check
fix: add job-id verification-check
2 parents c7dfb78 + 1cd49e2 commit f980327

File tree

18 files changed

+282
-23
lines changed

18 files changed

+282
-23
lines changed

defs/src/deployment.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ pub struct DeploymentResp {
9090
pub reference: String,
9191
}
9292

93+
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
94+
#[derive(Deserialize, Clone, Debug, Serialize)]
95+
pub struct JobStatus {
96+
pub job_id: String,
97+
pub is_running: bool,
98+
}
99+
93100
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
94101
#[derive(Debug, Clone, Deserialize, Serialize)]
95102
pub struct Dependency {

defs/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ mod stack;
1919
pub use api::GenericFunctionResponse;
2020
pub use deployment::{
2121
get_deployment_identifier, Dependency, Dependent, DeploymentManifest, DeploymentResp,
22-
DeploymentSpec, DriftDetection, Metadata as DeploymentMetadata, ProjectData, Webhook,
23-
DEFAULT_DRIFT_DETECTION_INTERVAL,
22+
DeploymentSpec, DriftDetection, JobStatus, Metadata as DeploymentMetadata, ProjectData,
23+
Webhook, DEFAULT_DRIFT_DETECTION_INTERVAL,
2424
};
2525
pub use environment::EnvironmentResp;
2626
pub use errors::CloudHandlerError;

defs/src/provider.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::{future::Future, pin::Pin};
22

33
use crate::{
4-
Dependent, DeploymentResp, EventData, GenericFunctionResponse, InfraChangeRecord, LogData,
5-
ModuleResp, NotificationData, PolicyResp, ProjectData,
4+
deployment::JobStatus, Dependent, DeploymentResp, EventData, GenericFunctionResponse,
5+
InfraChangeRecord, LogData, ModuleResp, NotificationData, PolicyResp, ProjectData,
66
};
77

88
use async_trait::async_trait;
@@ -116,6 +116,7 @@ pub trait CloudProvider: Send + Sync {
116116
environment: &str,
117117
include_deleted: bool,
118118
) -> Result<Option<DeploymentResp>, anyhow::Error>;
119+
async fn get_job_status(&self, job_id: &str) -> Result<Option<JobStatus>, anyhow::Error>;
119120
async fn get_deployments_using_module(
120121
&self,
121122
module: &str,

env_aws/src/api.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,15 @@ pub fn get_generate_presigned_url_query(key: &str, bucket: &str) -> Value {
304304
})
305305
}
306306

307+
pub fn get_job_status_query(job_id: &str) -> Value {
308+
json!({
309+
"event": "get_job_status",
310+
"data": {
311+
"job_id": job_id
312+
}
313+
})
314+
}
315+
307316
pub fn get_all_deployments_query(project_id: &str, region: &str, environment: &str) -> Value {
308317
json!({
309318
"IndexName": "DeletedIndex",

env_aws/src/job_id.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::env;
1111

1212
pub async fn get_current_job_id() -> Result<String, anyhow::Error> {
1313
if std::env::var("TEST_MODE").is_ok() {
14-
return Ok("test-job-id".to_string());
14+
return Ok("running-test-job-id".to_string());
1515
};
1616

1717
let metadata_uri = env::var("ECS_CONTAINER_METADATA_URI_V4")

env_aws/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub use api::{
2525
get_deployments_using_module_query,
2626
get_events_query,
2727
get_generate_presigned_url_query,
28+
get_job_status_query,
2829
get_latest_module_version_query,
2930
get_latest_stack_version_query,
3031
get_module_version_query,

env_aws/src/provider.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use async_trait::async_trait;
22
use env_defs::{
33
CloudHandlerError, CloudProvider, Dependent, DeploymentResp, EventData,
4-
GenericFunctionResponse, InfraChangeRecord, ModuleResp, PolicyResp, ProjectData,
4+
GenericFunctionResponse, InfraChangeRecord, JobStatus, ModuleResp, PolicyResp, ProjectData,
55
};
66
use env_utils::{
77
_get_change_records, _get_dependents, _get_deployment, _get_deployment_and_dependents,
@@ -147,6 +147,22 @@ impl CloudProvider for AwsCloudProvider {
147147
) -> Result<Option<ModuleResp>, anyhow::Error> {
148148
_get_module_optional(self, crate::get_latest_stack_version_query(stack, track)).await
149149
}
150+
async fn get_job_status(&self, job_id: &str) -> Result<Option<JobStatus>, anyhow::Error> {
151+
match crate::run_function(
152+
&self.function_endpoint,
153+
&crate::get_job_status_query(job_id),
154+
&self.project_id,
155+
&self.region,
156+
)
157+
.await
158+
{
159+
Ok(response) => {
160+
let job_status: JobStatus = serde_json::from_value(response.payload)?;
161+
Ok(Some(job_status))
162+
}
163+
Err(e) => Err(e.into()),
164+
}
165+
}
150166
async fn generate_presigned_url(
151167
&self,
152168
key: &str,

env_azure/src/api.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,15 @@ pub fn get_generate_presigned_url_query(key: &str, bucket: &str) -> Value {
176176
})
177177
}
178178

179+
pub fn get_job_status_query(job_id: &str) -> Value {
180+
json!({
181+
"event": "get_job_status",
182+
"data": {
183+
"job_id": job_id
184+
}
185+
})
186+
}
187+
179188
pub fn get_all_latest_modules_query(track: &str) -> Value {
180189
_get_all_latest_modules_query("LATEST_MODULE", track)
181190
}

env_azure/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub use api::{
2525
get_deployments_using_module_query,
2626
get_events_query,
2727
get_generate_presigned_url_query,
28+
get_job_status_query,
2829
get_latest_module_version_query,
2930
get_latest_stack_version_query,
3031
get_module_version_query,

env_azure/src/provider.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use async_trait::async_trait;
22
use env_defs::{
33
CloudProvider, Dependent, DeploymentResp, EventData, GenericFunctionResponse,
4-
InfraChangeRecord, ModuleResp, PolicyResp, ProjectData,
4+
InfraChangeRecord, JobStatus, ModuleResp, PolicyResp, ProjectData,
55
};
66
use env_utils::{
77
_get_change_records, _get_dependents, _get_deployment, _get_deployment_and_dependents,
@@ -123,6 +123,22 @@ impl CloudProvider for AzureCloudProvider {
123123
) -> Result<Option<ModuleResp>, anyhow::Error> {
124124
_get_module_optional(self, crate::get_latest_stack_version_query(stack, track)).await
125125
}
126+
async fn get_job_status(&self, job_id: &str) -> Result<Option<JobStatus>, anyhow::Error> {
127+
match crate::run_function(
128+
&self.function_endpoint,
129+
&crate::get_job_status_query(job_id),
130+
&self.project_id,
131+
&self.region,
132+
)
133+
.await
134+
{
135+
Ok(response) => {
136+
let job_status: JobStatus = serde_json::from_value(response.payload)?;
137+
Ok(Some(job_status))
138+
}
139+
Err(e) => Err(e),
140+
}
141+
}
126142
async fn generate_presigned_url(
127143
&self,
128144
key: &str,

0 commit comments

Comments
 (0)