diff --git a/backend/migrations/20220624170622_workspace_premium.down.sql b/backend/migrations/20220624170622_workspace_premium.down.sql new file mode 100644 index 0000000000..d2f607c5b8 --- /dev/null +++ b/backend/migrations/20220624170622_workspace_premium.down.sql @@ -0,0 +1 @@ +-- Add down migration script here diff --git a/backend/migrations/20220624170622_workspace_premium.up.sql b/backend/migrations/20220624170622_workspace_premium.up.sql new file mode 100644 index 0000000000..ae56dfcb47 --- /dev/null +++ b/backend/migrations/20220624170622_workspace_premium.up.sql @@ -0,0 +1,2 @@ +-- Add up migration script here +ALTER TABLE workspace ADD COLUMN premium BOOLEAN NOT NULL DEFAULT false; diff --git a/backend/src/jobs.rs b/backend/src/jobs.rs index c4bb474e78..7159b3b409 100644 --- a/backend/src/jobs.rs +++ b/backend/src/jobs.rs @@ -1006,22 +1006,28 @@ pub async fn push<'c>( let args_json = args.map(serde_json::Value::Object); let job_id: Uuid = Ulid::new().into(); - let rate_limiting_queue = sqlx::query_scalar!( - "SELECT COUNT(id) FROM queue WHERE created_by = $1 AND workspace_id = $2", - user, - workspace_id - ) - .fetch_one(&mut tx) - .await?; + let premium_workspace = + sqlx::query_scalar!("SELECT premium FROM workspace WHERE id = $1", workspace_id) + .fetch_one(&mut tx) + .await?; - if let Some(nb_jobs) = rate_limiting_queue { - if nb_jobs > MAX_NB_OF_JOBS_IN_Q_PER_USER { - return Err(error::Error::ExecutionErr(format!( + if !premium_workspace && std::env::var("CLOUD_HOSTED").is_ok() { + let rate_limiting_queue = sqlx::query_scalar!( + "SELECT COUNT(id) FROM queue WHERE created_by = $1 AND workspace_id = $2", + user, + workspace_id + ) + .fetch_one(&mut tx) + .await?; + + if let Some(nb_jobs) = rate_limiting_queue { + if nb_jobs > MAX_NB_OF_JOBS_IN_Q_PER_USER { + return Err(error::Error::ExecutionErr(format!( "You have exceeded the number of authorized elements of queue at any given time: {}", MAX_NB_OF_JOBS_IN_Q_PER_USER))); + } } - } - let rate_limiting_duration = sqlx::query_scalar!( + let rate_limiting_duration = sqlx::query_scalar!( "SELECT SUM(duration) FROM completed_job WHERE created_by = $1 AND created_at > NOW() - INTERVAL '1200 seconds' AND workspace_id = $2", user, workspace_id @@ -1029,10 +1035,11 @@ pub async fn push<'c>( .fetch_one(&mut tx) .await?; - if let Some(sum_duration) = rate_limiting_duration { - if sum_duration > MAX_DURATION_LAST_1200 { - return Err(error::Error::ExecutionErr(format!( + if let Some(sum_duration) = rate_limiting_duration { + if sum_duration > MAX_DURATION_LAST_1200 { + return Err(error::Error::ExecutionErr(format!( "You have exceeded the scripts cumulative duration limit over the last 20m which is: {}", MAX_DURATION_LAST_1200))); + } } } diff --git a/backend/src/workspaces.rs b/backend/src/workspaces.rs index f3f76c242e..504dc041b6 100644 --- a/backend/src/workspaces.rs +++ b/backend/src/workspaces.rs @@ -53,7 +53,8 @@ struct Workspace { name: String, owner: String, domain: Option, - deleted: bool + deleted: bool, + premium: bool } #[derive(FromRow, Serialize, Debug)]