Skip to content

Commit 5b281b1

Browse files
mihaelabalutoiuDany9966
authored andcommitted
Refresh execution timeline statuses while active
Timeline statuses used to be merged from the executions embedded in the transfer details response. Since those are no longer returned, refresh the current page from the executions endpoint during polling instead. Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
1 parent 1473475 commit 5b281b1

2 files changed

Lines changed: 73 additions & 43 deletions

File tree

src/sources/TransferSource.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ class TransferSource {
151151
limit?: number;
152152
marker?: string | null;
153153
quietError?: boolean;
154+
sortKeys?: string[];
155+
sortDirs?: string[];
154156
},
155157
): Promise<Execution[]> {
156158
const params: string[] = [];
@@ -160,6 +162,12 @@ class TransferSource {
160162
if (options?.limit !== undefined) {
161163
params.push(`limit=${options.limit}`);
162164
}
165+
options?.sortKeys?.forEach(key => {
166+
params.push(`sort_keys=${encodeURIComponent(key)}`);
167+
});
168+
options?.sortDirs?.forEach(dir => {
169+
params.push(`sort_dirs=${encodeURIComponent(dir)}`);
170+
});
163171
const queryString = params.length > 0 ? `?${params.join("&")}` : "";
164172
const response = await Api.send({
165173
url: `${configLoader.config.servicesUrls.coriolis}/${Api.projectId}/transfers/${transferId}/executions${queryString}`,

src/stores/TransferStore.ts

Lines changed: 65 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
1414

1515
import { observable, action, runInAction } from "mobx";
1616

17-
import TransferSource, {
18-
TransferSourceUtils,
19-
sortTasks,
20-
} from "@src/sources/TransferSource";
17+
import TransferSource from "@src/sources/TransferSource";
2118
import type {
2219
UpdateData,
2320
TransferItem,
@@ -123,9 +120,11 @@ class TransferStore {
123120
try {
124121
const raw = await TransferSource.getExecutions(transferId, {
125122
limit: this.executionsPageSize,
123+
sortKeys: ["number"],
124+
sortDirs: ["desc"],
126125
});
127126
const hasOlderPage = raw.length === this.executionsPageSize;
128-
TransferSourceUtils.sortExecutions(raw);
127+
raw.reverse();
129128
runInAction(() => {
130129
this.executionsList = raw;
131130
this.executionsHasOlderPage = hasOlderPage;
@@ -162,9 +161,11 @@ class TransferStore {
162161
limit: this.executionsPageSize,
163162
marker,
164163
quietError: true,
164+
sortKeys: ["number"],
165+
sortDirs: ["desc"],
165166
});
166167
const hasOlderPage = raw.length === this.executionsPageSize;
167-
TransferSourceUtils.sortExecutions(raw);
168+
raw.reverse();
168169
runInAction(() => {
169170
this.executionsList = [...raw, ...this.executionsList];
170171
this.executionsHasOlderPage = hasOlderPage;
@@ -268,48 +269,67 @@ class TransferStore {
268269
includeTaskInfo,
269270
});
270271

272+
const activeStatuses = [
273+
"RUNNING",
274+
"PENDING",
275+
"CANCELLING",
276+
"AWAITING_MINION_ALLOCATIONS",
277+
];
278+
const newestExecution =
279+
this.executionsList[this.executionsList.length - 1];
280+
const hasActiveExecution =
281+
activeStatuses.includes(transfer.last_execution_status) ||
282+
(newestExecution != null &&
283+
activeStatuses.includes(newestExecution.status));
284+
const shouldRefreshExecutions =
285+
this.executionsList.length > 0 && (!polling || hasActiveExecution);
286+
let freshExecutions: Execution[] | null = null;
287+
if (shouldRefreshExecutions) {
288+
try {
289+
freshExecutions = await TransferSource.getExecutions(transferId, {
290+
limit: this.executionsPageSize,
291+
quietError: polling,
292+
sortKeys: ["number"],
293+
sortDirs: ["desc"],
294+
});
295+
freshExecutions.reverse();
296+
} catch (err) {
297+
console.error(err);
298+
}
299+
}
300+
271301
runInAction(() => {
272302
this.transferDetails = transfer;
273-
let statusChanged = false;
274-
const updatedList = this.executionsList.map(e => {
275-
const fresh = transfer.executions?.find(te => te.id === e.id);
276-
if (fresh && fresh.status !== e.status) {
277-
statusChanged = true;
278-
return { ...e, status: fresh.status };
279-
}
280-
return e;
281-
});
282-
if (statusChanged) {
283-
this.executionsList = updatedList;
284-
}
285303

286-
if (this.executionsList.length > 0 && transfer.executions?.length) {
287-
const newestNumber = Math.max(
288-
...this.executionsList.map(e => e.number),
289-
);
290-
const incoming = transfer.executions.filter(
291-
e =>
292-
e.number > newestNumber &&
293-
!this.deletedExecutionIds.has(e.id) &&
294-
!this.executionsList.find(l => l.id === e.id),
295-
);
296-
if (incoming.length > 0) {
297-
TransferSourceUtils.sortExecutions(incoming);
298-
this.executionsList = [...this.executionsList, ...incoming];
304+
if (freshExecutions) {
305+
let statusChanged = false;
306+
const updatedList = this.executionsList.map(e => {
307+
const fresh = freshExecutions!.find(te => te.id === e.id);
308+
if (fresh && fresh.status !== e.status) {
309+
statusChanged = true;
310+
return { ...e, status: fresh.status };
311+
}
312+
return e;
313+
});
314+
if (statusChanged) {
315+
this.executionsList = updatedList;
299316
}
300-
}
301317

302-
transfer.executions?.forEach(exec => {
303-
const withTasks = exec as ExecutionTasks;
304-
if (
305-
Array.isArray(withTasks.tasks) &&
306-
!this.deletedExecutionIds.has(exec.id) &&
307-
!this.executionsTasks.find(et => et.id === exec.id)
308-
) {
309-
sortTasks(withTasks.tasks, TransferSourceUtils.sortTaskUpdates);
310-
this.executionsTasks = [...this.executionsTasks, withTasks];
318+
if (this.executionsList.length > 0) {
319+
const newestNumber = Math.max(
320+
...this.executionsList.map(e => e.number),
321+
);
322+
const incoming = freshExecutions.filter(
323+
e =>
324+
e.number > newestNumber &&
325+
!this.deletedExecutionIds.has(e.id) &&
326+
!this.executionsList.find(l => l.id === e.id),
327+
);
328+
if (incoming.length > 0) {
329+
this.executionsList = [...this.executionsList, ...incoming];
330+
}
311331
}
312-
});
332+
}
313333
});
314334
} finally {
315335
runInAction(() => {
@@ -561,8 +581,10 @@ class TransferStore {
561581
const executions = await TransferSource.getExecutions(transfer.id, {
562582
limit: this.executionsPageSize,
563583
quietError: true,
584+
sortKeys: ["number"],
585+
sortDirs: ["desc"],
564586
});
565-
TransferSourceUtils.sortExecutions(executions);
587+
executions.reverse();
566588
return { transfer, hasDisks: this.testTransferHasDisks(executions) };
567589
}),
568590
);

0 commit comments

Comments
 (0)