Skip to content

Commit

Permalink
add suspended flows to cli queues
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenfiszel committed Sep 26, 2024
1 parent 8e0eb3d commit bca4099
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
2 changes: 2 additions & 0 deletions backend/windmill-api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9987,6 +9987,8 @@ components:
type: number
aggregate_wait_time_ms:
type: number
suspend:
type: number
required:
- id
- running
Expand Down
2 changes: 1 addition & 1 deletion backend/windmill-api/src/jobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,7 @@ pub fn list_queue_jobs_query(
join_outstanding_wait_times: bool,
tags: Option<Vec<&str>>,
) -> SqlBuilder {
let (limit, offset) = paginate(pagination);
let (limit, offset) = paginate_without_limits(pagination);
let mut sqlb = SqlBuilder::select_from("queue")
.fields(fields)
.order_by("created_at", lq.order_desc.unwrap_or(true))
Expand Down
6 changes: 6 additions & 0 deletions backend/windmill-common/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ pub fn paginate(pagination: Pagination) -> (usize, usize) {
(per_page, offset)
}

pub fn paginate_without_limits(pagination: Pagination) -> (usize, usize) {
let per_page = pagination.per_page.unwrap_or(MAX_PER_PAGE);
let offset = (pagination.page.unwrap_or(1).max(1) - 1) * per_page;
(per_page, offset)
}

pub async fn now_from_db<'c, E: sqlx::PgExecutor<'c>>(
db: E,
) -> Result<chrono::DateTime<chrono::Utc>> {
Expand Down
1 change: 1 addition & 0 deletions cli/gen/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export type QueuedJob = {
priority?: number;
self_wait_time_ms?: number;
aggregate_wait_time_ms?: number;
suspend?: number;
};

export type job_kind = 'script' | 'preview' | 'dependencies' | 'flowdependencies' | 'appdependencies' | 'flow' | 'flowpreview' | 'script_hub' | 'identity' | 'deploymentcallback' | 'singlescriptflow';
Expand Down
13 changes: 10 additions & 3 deletions cli/queues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { pickInstance } from "./instance.ts";
type Data = {
count: number;
later: number;
suspended: number;
waiting: number;
running: number;
rps30s: string;
Expand All @@ -29,6 +30,7 @@ function createRow(tag: string, data: Record<string, Data>) {
waiting: 0,
later: 0,
running: 0,
suspended: 0,
rps30s: "",
rps5min: "",
rps30min: "",
Expand All @@ -40,7 +42,7 @@ async function displayQueues(opts: GlobalOptions, workspace?: string) {
const activeInstance = await pickInstance(opts, true);
if (activeInstance) {
try {
const queuedJobs = await wmill.listQueue({workspace: workspace ?? 'admins', allWorkspaces: workspace === undefined});
const queuedJobs = await wmill.listQueue({workspace: workspace ?? 'admins', allWorkspaces: workspace === undefined, perPage: 100000});
const jobCounts30s = await wmill.countJobsByTag({
horizonSecs: 30,
workspaceId: workspace,
Expand Down Expand Up @@ -68,7 +70,11 @@ async function displayQueues(opts: GlobalOptions, workspace?: string) {
createRow(job.tag, data);
const scheduledFor = new Date(job.scheduled_for ?? "");
if (job.running) {
data[job.tag].running += 1;
if (job.suspend) {
data[job.tag].suspended += 1;
} else {
data[job.tag].running += 1;
}
} else if (scheduledFor <= nowFromDb) {
data[job.tag].waiting += 1;
} else {
Expand Down Expand Up @@ -104,14 +110,15 @@ async function displayQueues(opts: GlobalOptions, workspace?: string) {
"Running",
"Waiting",
"Later",
"Suspended",
"RPS (30s)",
"RPS (5min)",
"RPS (30min)",
"RPS (24h)",
]);
let body = []
for (const tag in data) {
body.push([tag, data[tag].running, data[tag].waiting, data[tag].later, data[tag].rps30s, data[tag].rps5min, data[tag].rps30min, data[tag].rps24h]);
body.push([tag, data[tag].running, data[tag].waiting, data[tag].later, data[tag].suspended, data[tag].rps30s, data[tag].rps5min, data[tag].rps30min, data[tag].rps24h]);
}
table.body(body).render();

Expand Down

0 comments on commit bca4099

Please sign in to comment.