Skip to content

Bubble running workflows to top #2528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions backend/btrixcloud/crawlconfigs.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ async def get_crawl_configs(
description: Optional[str] = None,
tags: Optional[List[str]] = None,
schedule: Optional[bool] = None,
running: Optional[bool] = None,
sort_by: str = "lastRun",
sort_direction: int = -1,
) -> tuple[list[CrawlConfigOut], int]:
Expand All @@ -569,6 +570,9 @@ async def get_crawl_configs(
if description:
match_query["description"] = description

if running is not None:
match_query["isCrawlRunning"] = running

if schedule is not None:
if schedule:
match_query["schedule"] = {"$nin": ["", None]}
Expand Down Expand Up @@ -1294,6 +1298,7 @@ async def get_crawl_configs(
schedule: Optional[bool] = None,
sortBy: str = "",
sortDirection: int = -1,
running: Optional[bool] = None,
):
# pylint: disable=duplicate-code
if firstSeed:
Expand All @@ -1314,6 +1319,7 @@ async def get_crawl_configs(
description=description,
tags=tag,
schedule=schedule,
running=running,
page_size=pageSize,
page=page,
sort_by=sortBy,
Expand Down
85 changes: 85 additions & 0 deletions frontend/src/pages/org/workflows-list-group-controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { Task } from "@lit/task";
import { type ReactiveController } from "lit";
import queryString from "query-string";

import { type Workflow } from "./types";

import { type WorkflowsList } from "@/pages/org/workflows-list";
import { type APIPaginatedList } from "@/types/api";
import { type UserInfo } from "@/types/user";

const stringifyQuery = (query: {}) =>
queryString.stringify(query, {
arrayFormat: "comma",
});

export class ClockController implements ReactiveController {
host: WorkflowsList;

private readonly POLL_INTERVAL_SECONDS;
private runningIntervalId?: number;
private allIntervalId?: number;

Check warning on line 21 in frontend/src/pages/org/workflows-list-group-controller.ts

View workflow job for this annotation

GitHub Actions / Lint (20)

Member 'allIntervalId' is never reassigned; mark it as `readonly`

Check warning on line 21 in frontend/src/pages/org/workflows-list-group-controller.ts

View workflow job for this annotation

GitHub Actions / Lint (22)

Member 'allIntervalId' is never reassigned; mark it as `readonly`

readonly task;

constructor(
host: WorkflowsList,
INITIAL_PAGE_SIZE = 10,
POLL_INTERVAL_SECONDS = 10,
userInfo: () => UserInfo | undefined,
) {
(this.host = host).addController(this);
this.POLL_INTERVAL_SECONDS = POLL_INTERVAL_SECONDS;
this.task = new Task(this.host, {
task: async (
[showRunningFirst, filterBy, orderBy, page, filterByCurrentUser],
{ signal },
) => {
if (!showRunningFirst) {
return;
}
const queryParams = {
...filterBy,
page: page || 1,
pageSize: this.task.value?.pageSize || INITIAL_PAGE_SIZE,
userid: filterByCurrentUser ? userInfo()?.id : undefined,
sortBy: orderBy.field,
sortDirection: orderBy.direction === "desc" ? -1 : 1,
running: true,
} as const;

const query = stringifyQuery(queryParams);

const workflows = await this.host.api.fetch<APIPaginatedList<Workflow>>(
`/orgs/${this.host.orgId}/crawlconfigs?${query}`,
{
signal: signal,
},
);

signal.addEventListener("abort", () => {
clearTimeout(this.runningIntervalId);
this.runningIntervalId = undefined;
});

clearTimeout(this.allIntervalId);

this.runningIntervalId = window.setTimeout(() => {
void this.task.run();
}, 1000 * POLL_INTERVAL_SECONDS);

return workflows;
},
args: () =>
[
this.host.showRunningFirst,
this.host.filterBy,
this.host.orderBy,
this.host.page[WorkflowGroup.RUNNING],
this.host.filterByCurrentUser,
] as const,
});
}
hostConnected() {}
hostDisconnected() {}
}
Loading
Loading