Skip to content

Commit

Permalink
edits
Browse files Browse the repository at this point in the history
  • Loading branch information
just-in-chang committed Oct 9, 2024
1 parent 41c10a1 commit 8d47a75
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
DROP INDEX IF EXISTS asset_uploader_request_status_code;
DROP TABLE IF EXISTS nft_metadata_crawler.asset_uploader_request_statuses;
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ CREATE TABLE nft_metadata_crawler.asset_uploader_request_statuses (
request_id UUID NOT NULL,
asset_uri VARCHAR NOT NULL,
application_id UUID NOT NULL,
status_code BIGINT,
status_code BIGINT NOT NULL DEFAULT 202,
error_message VARCHAR,
cdn_image_uri VARCHAR,
num_failures BIGINT NOT NULL DEFAULT 0,
inserted_at TIMESTAMP NOT NULL DEFAULT NOW(),
PRIMARY KEY (request_id, asset_uri)
);
CREATE INDEX IF NOT EXISTS asset_uploader_request_status_code ON nft_metadata_crawler.asset_uploader_request_statuses (status_code);
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{
models::asset_uploader_request_statuses_query::AssetUploaderRequestStatusesQuery, schema,
};
use ahash::AHashMap;
use axum::http::StatusCode;
use diesel::{
r2d2::{ConnectionManager, Pool, PooledConnection},
ExpressionMethods, PgConnection, QueryDsl, RunQueryDsl,
Expand All @@ -23,28 +24,17 @@ pub fn get_status(
let mut status_response = AHashMap::new();
let rows = query_status(&mut conn, &request_id)?;
for row in rows {
let status_code = row.status_code.map(|x| x as u16);

let response = if let Some(status_code) = status_code {
if status_code == 200 {
GetStatusResponseSuccess::Success {
status_code: Some(status_code),
cdn_image_uri: row.cdn_image_uri.unwrap_or_default(),
}
} else {
GetStatusResponseSuccess::Error {
status_code: Some(status_code),
error_message: row.error_message,
}
}
if row.status_code == StatusCode::OK.as_u16() as i64 {
status_response.insert(row.asset_uri, GetStatusResponseSuccess::Success {
status_code: StatusCode::OK.as_u16(),
cdn_image_uri: row.cdn_image_uri.unwrap_or_default(),
});
} else {
GetStatusResponseSuccess::Error {
status_code,
status_response.insert(row.asset_uri, GetStatusResponseSuccess::Error {
status_code: row.status_code as u16,
error_message: row.error_message,
}
});
};

status_response.insert(row.asset_uri, response);
}

Ok(status_response)
Expand Down
4 changes: 2 additions & 2 deletions ecosystem/nft-metadata-crawler/src/asset_uploader/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ enum BatchUploadResponse {
#[serde(untagged)]
pub enum GetStatusResponseSuccess {
Success {
status_code: Option<u16>,
status_code: u16,
cdn_image_uri: String,
},
Error {
status_code: Option<u16>,
status_code: u16,
error_message: Option<String>,
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

use crate::schema::nft_metadata_crawler::asset_uploader_request_statuses;
use axum::http::StatusCode;
use diesel::prelude::*;
use field_count::FieldCount;
use serde::{Deserialize, Serialize};
Expand All @@ -14,7 +15,7 @@ pub struct AssetUploaderRequestStatuses {
request_id: Uuid,
asset_uri: String,
application_id: Uuid,
status_code: Option<i64>,
status_code: i64,
error_message: Option<String>,
cdn_image_uri: Option<String>,
num_failures: i64,
Expand All @@ -26,7 +27,7 @@ impl AssetUploaderRequestStatuses {
request_id,
asset_uri: asset_uri.to_string(),
application_id,
status_code: None,
status_code: StatusCode::ACCEPTED.as_u16() as i64,
error_message: None,
cdn_image_uri: None,
num_failures: 0,
Expand All @@ -43,54 +44,10 @@ impl AssetUploaderRequestStatuses {
request_id,
asset_uri: asset_uri.to_string(),
application_id,
status_code: Some(200),
status_code: StatusCode::OK.as_u16() as i64,
error_message: None,
cdn_image_uri: Some(cdn_image_uri.to_string()),
num_failures: 0,
}
}

pub fn get_request_id(&self) -> Uuid {
self.request_id
}

pub fn get_asset_uri(&self) -> String {
self.asset_uri.clone()
}

pub fn get_application_id(&self) -> Uuid {
self.application_id
}

pub fn get_status_code(&self) -> Option<i64> {
self.status_code
}

pub fn set_status_code(&mut self, status_code: Option<i64>) {
self.status_code = status_code;
}

pub fn get_error_message(&self) -> Option<String> {
self.error_message.clone()
}

pub fn set_error_message(&mut self, error_message: Option<String>) {
self.error_message = error_message;
}

pub fn get_cdn_image_uri(&self) -> Option<String> {
self.cdn_image_uri.clone()
}

pub fn set_cdn_image_uri(&mut self, cdn_image_uri: Option<String>) {
self.cdn_image_uri = cdn_image_uri;
}

pub fn get_num_failures(&self) -> i64 {
self.num_failures
}

pub fn increment_num_failures(&mut self) {
self.num_failures += 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct AssetUploaderRequestStatusesQuery {
pub request_id: Uuid,
pub asset_uri: String,
pub application_id: Uuid,
pub status_code: Option<i64>,
pub status_code: i64,
pub error_message: Option<String>,
pub cdn_image_uri: Option<String>,
pub num_failures: i64,
Expand Down
2 changes: 1 addition & 1 deletion ecosystem/nft-metadata-crawler/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub mod nft_metadata_crawler {
request_id -> Uuid,
asset_uri -> Varchar,
application_id -> Uuid,
status_code -> Nullable<Int8>,
status_code -> Int8,
error_message -> Nullable<Varchar>,
cdn_image_uri -> Nullable<Varchar>,
num_failures -> Int8,
Expand Down

0 comments on commit 8d47a75

Please sign in to comment.