Skip to content

Commit

Permalink
feat(taskView): Implement opt-in paginated request for TaskView (spin…
Browse files Browse the repository at this point in the history
…naker#10093)

* feat(tasksview): Allowing opt-in pagination for tasks view loading

* feat(taskView): Implement opt-in paginated request for TaskView
  • Loading branch information
christosarvanitis committed May 7, 2024
1 parent 93bab65 commit 5fa1e96
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/core/src/config/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export interface ISpinnakerSettings {
};
stashTriggerInfo?: string;
pollSchedule: number;
tasksViewLimitPerPage: number;
providers?: {
[key: string]: IProviderSettings; // allows custom providers not typed in here (good for testing too)
};
Expand Down
20 changes: 18 additions & 2 deletions packages/core/src/task/task.dataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as angular from 'angular';

import { ApplicationDataSourceRegistry } from '../application/service/ApplicationDataSourceRegistry';
import { CLUSTER_SERVICE } from '../cluster/cluster.service';
import { SETTINGS } from '../config';
import { TaskReader } from './task.read.service';

export const CORE_TASK_TASK_DATASOURCE = 'spinnaker.core.task.dataSource';
Expand All @@ -14,8 +15,23 @@ angular.module(CORE_TASK_TASK_DATASOURCE, [CLUSTER_SERVICE]).run([
return $q.when(angular.isArray(tasks) ? tasks : []);
};

const loadTasks = (application) => {
return TaskReader.getTasks(application.name);
const loadPaginatedTasks = async (application, page = 1) => {
let limitPerPage = SETTINGS.tasksViewLimitPerPage;
const tasks = await TaskReader.getTasks(application.name, [], limitPerPage, page);
if (tasks.length === limitPerPage) {
return tasks.concat(await loadPaginatedTasks(application, page + 1));
} else {
return tasks;
}
};

const loadTasks = (application, page = 1) => {
let limitPerPage = SETTINGS.tasksViewLimitPerPage;
if (limitPerPage === undefined) {
return TaskReader.getTasks(application.name);
} else {
return loadPaginatedTasks(application, page);
}
};

const loadRunningTasks = (application) => {
Expand Down
13 changes: 11 additions & 2 deletions packages/core/src/task/task.read.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@ import { OrchestratedItemTransformer } from '../orchestratedItem/orchestratedIte
export class TaskReader {
private static activeStatuses: string[] = ['RUNNING', 'SUSPENDED', 'NOT_STARTED'];

public static getTasks(applicationName: string, statuses: string[] = []): PromiseLike<ITask[]> {
public static getTasks(
applicationName: string,
statuses: string[] = [],
limitPerPage: number = null,
page: number = null,
): PromiseLike<ITask[]> {
return REST('/applications')
.path(applicationName, 'tasks')
.query({ statuses: statuses.join(',') })
.query({
statuses: statuses.join(','),
limit: limitPerPage,
page: page,
})
.get()
.then((tasks: ITask[]) => {
tasks.forEach((task) => this.setTaskProperties(task));
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18292,10 +18292,10 @@ vite-plugin-svgr@^0.3.0:
dependencies:
"@svgr/core" "^5.5.0"

vite@2.9.16:
version "2.9.16"
resolved "https://registry.yarnpkg.com/vite/-/vite-2.9.16.tgz#daf7ba50f5cc37a7bf51b118ba06bc36e97898e9"
integrity sha512-X+6q8KPyeuBvTQV8AVSnKDvXoBMnTx8zxh54sOwmmuOdxkjMmEJXH2UEchA+vTMps1xw9vL64uwJOWryULg7nA==
vite@2.9.18:
version "2.9.18"
resolved "https://registry.yarnpkg.com/vite/-/vite-2.9.18.tgz#74e2a83b29da81e602dac4c293312cc575f091c7"
integrity sha512-sAOqI5wNM9QvSEE70W3UGMdT8cyEn0+PmJMTFvTB8wB0YbYUWw3gUbY62AOyrXosGieF2htmeLATvNxpv/zNyQ==
dependencies:
esbuild "^0.14.27"
postcss "^8.4.13"
Expand Down

0 comments on commit 5fa1e96

Please sign in to comment.