@posiwise/flows 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,8 +5,8 @@ import { RouterModule } from "@angular/router";
5
5
  import * as i3$1 from "@posiwise/core-guards";
6
6
  import { PageAccessGuard, TrackDirtyFormDirective } from "@posiwise/core-guards";
7
7
  import { AppBaseComponent } from "@posiwise/app-base-component";
8
- import { Subject, combineLatest, forkJoin, of, throwError, timer } from "rxjs";
9
- import { catchError, distinctUntilChanged, exhaustMap, finalize, map, shareReplay, switchMap, takeUntil, takeWhile, tap } from "rxjs/operators";
8
+ import { EMPTY, Subject, combineLatest, defer, forkJoin, of, throwError, timer } from "rxjs";
9
+ import { catchError, distinctUntilChanged, finalize, map, repeat, shareReplay, switchMap, takeUntil, takeWhile, tap } from "rxjs/operators";
10
10
  import { faArrowAltCircleLeft, faBolt, faChevronDown, faChevronRight, faCircleCheck, faCircleExclamation, faCode, faCodeBranch, faCopy, faDiagramProject, faExpand, faEye, faLayerGroup, faMagnifyingGlass, faPaperPlane, faPause, faPenToSquare, faPlay, faPlusCircle, faTableList, faTrash, faTriangleExclamation } from "@fortawesome/free-solid-svg-icons";
11
11
  import { FLOWS_NODES_PATH, FLOWS_RUNS_PATH, FLOWS_RUN_POLL_INTERVAL_MS, FLOWS_VERSIONS_PATH, FLOWS_WORKFLOWS_PATH } from "@posiwise/flows-shared";
12
12
  import * as i1$3 from "@posiwise/shared-product-services";
@@ -230,6 +230,12 @@ function toFlowWorkflowFields(rows) {
230
230
  ran: list.length > 0
231
231
  };
232
232
  }
233
+ const FLOWS_RUNS_IDLE_POLL_INTERVAL_MS = 15e3;
234
+ const FLOWS_POLL_BACKOFF_MS = 3e4;
235
+ const FLOWS_POLL_MAX_BACKOFF_MS = 12e4;
236
+ function flowsPollDelay(intervalMs, failures) {
237
+ return failures ? Math.min(FLOWS_POLL_BACKOFF_MS * 2 ** (failures - 1), FLOWS_POLL_MAX_BACKOFF_MS) : intervalMs;
238
+ }
233
239
  var FlowsRunService = class FlowsRunService {
234
240
  constructor(api) {
235
241
  this.api = api;
@@ -252,13 +258,34 @@ var FlowsRunService = class FlowsRunService {
252
258
  });
253
259
  }
254
260
  watchRuns(subscriptionId, query = {}, paging) {
255
- return timer(0, FLOWS_RUN_POLL_INTERVAL_MS).pipe(exhaustMap(() => this.getRuns(subscriptionId, query, paging)), takeWhile((response) => this.hasUnsettledRun(response), true));
261
+ return defer(() => {
262
+ let unsettled = false;
263
+ let failures = 0;
264
+ return defer(() => this.getRuns(subscriptionId, query, paging)).pipe(tap((response) => {
265
+ unsettled = this.hasUnsettledRun(response);
266
+ failures = 0;
267
+ }), catchError(() => {
268
+ failures += 1;
269
+ return of(null);
270
+ }), repeat({ delay: () => timer(flowsPollDelay(unsettled ? FLOWS_RUN_POLL_INTERVAL_MS : FLOWS_RUNS_IDLE_POLL_INTERVAL_MS, failures)) }));
271
+ });
256
272
  }
257
273
  watchRun(id, subscriptionId, paging) {
258
- return timer(0, FLOWS_RUN_POLL_INTERVAL_MS).pipe(exhaustMap(() => forkJoin({
259
- run: this.getRun(id, subscriptionId),
260
- steps: this.getRunSteps(id, subscriptionId, paging)
261
- })), map((detail) => detail), takeWhile((detail) => !isFlowRunTerminal(detail.run), true));
274
+ return defer(() => {
275
+ let loaded = false;
276
+ let failures = 0;
277
+ return defer(() => forkJoin({
278
+ run: this.getRun(id, subscriptionId),
279
+ steps: this.getRunSteps(id, subscriptionId, paging)
280
+ })).pipe(tap(() => {
281
+ loaded = true;
282
+ failures = 0;
283
+ }), catchError((error) => {
284
+ if (!loaded) return throwError(() => error);
285
+ failures += 1;
286
+ return EMPTY;
287
+ }), map((detail) => detail), repeat({ delay: () => timer(flowsPollDelay(FLOWS_RUN_POLL_INTERVAL_MS, failures)) }), takeWhile((detail) => !isFlowRunTerminal(detail.run), true));
288
+ });
262
289
  }
263
290
  hasUnsettledRun(response) {
264
291
  return (response?.flow_runs ?? []).some((run) => !isFlowRunTerminal(run));
@@ -1341,17 +1368,13 @@ var FlowsRunsComponent = class FlowsRunsComponent extends AppBaseComponent {
1341
1368
  page: this.page,
1342
1369
  page_size: this.PAGE_SIZE
1343
1370
  };
1344
- this.watch = this.flowsRunService.watchRuns(this.subscriptionId, this.query, paging).pipe(takeUntil(this.destroy$)).subscribe({
1345
- next: (response) => {
1371
+ this.watch = this.flowsRunService.watchRuns(this.subscriptionId, this.query, paging).pipe(takeUntil(this.destroy$)).subscribe((response) => {
1372
+ if (response) {
1346
1373
  this.runs = response.flow_runs ?? [];
1347
1374
  this.totalRecords = response.object_count ?? 0;
1348
1375
  this.totalRecordsUnFilter = response.unfiltered_count ?? 0;
1349
- this.settle();
1350
- },
1351
- error: () => {
1352
- this.runs = [];
1353
- this.settle();
1354
1376
  }
1377
+ this.settle();
1355
1378
  });
1356
1379
  }
1357
1380
  settle() {