remove quotas for premium workspaces

This commit is contained in:
Ruben Fiszel
2022-06-24 19:20:27 +02:00
parent 5bcb9f1db7
commit c22f0f2740
4 changed files with 27 additions and 16 deletions

View File

@@ -0,0 +1 @@
-- Add down migration script here

View File

@@ -0,0 +1,2 @@
-- Add up migration script here
ALTER TABLE workspace ADD COLUMN premium BOOLEAN NOT NULL DEFAULT false;

View File

@@ -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)));
}
}
}

View File

@@ -53,7 +53,8 @@ struct Workspace {
name: String,
owner: String,
domain: Option<String>,
deleted: bool
deleted: bool,
premium: bool
}
#[derive(FromRow, Serialize, Debug)]