@hmcts/ccd-case-ui-toolkit 7.3.53-body-parser-update → 7.3.53-polling
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.
|
@@ -8,11 +8,10 @@ import * as i1$1 from '@angular/router';
|
|
|
8
8
|
import { RouterModule, NavigationStart, NavigationEnd } from '@angular/router';
|
|
9
9
|
import * as i4 from '@angular/forms';
|
|
10
10
|
import { NG_VALUE_ACCESSOR, NG_VALIDATORS, FormArray, FormGroup, FormControl, Validators, ReactiveFormsModule, FormsModule } from '@angular/forms';
|
|
11
|
-
import { BehaviorSubject, throwError, Subject, EMPTY, Observable, skip, of,
|
|
11
|
+
import { BehaviorSubject, throwError, Subject, EMPTY, concat, defer, timer, Observable, skip, of, forkJoin, fromEvent, Subscription, combineLatest } from 'rxjs';
|
|
12
|
+
import { distinctUntilChanged, catchError, map, switchMap, repeat, retry, publish, refCount, debounceTime, delay, finalize, timeout, mergeMap, retryWhen, tap, delayWhen, publishReplay, take, first, takeUntil, filter } from 'rxjs/operators';
|
|
12
13
|
import * as i1$2 from '@angular/common/http';
|
|
13
14
|
import { HttpErrorResponse, HttpHeaders, HttpParams } from '@angular/common/http';
|
|
14
|
-
import { distinctUntilChanged, catchError, map, publish, refCount, switchMap, debounceTime, delay, finalize, timeout, mergeMap, retryWhen, tap, delayWhen, publishReplay, take, first, takeUntil, filter } from 'rxjs/operators';
|
|
15
|
-
import { polling } from 'rx-polling-hmcts';
|
|
16
15
|
import { Type, Exclude, Expose, plainToClassFromExist, plainToClass } from 'class-transformer';
|
|
17
16
|
import moment from 'moment';
|
|
18
17
|
import { __decorate, __metadata } from 'tslib';
|
|
@@ -1760,8 +1759,7 @@ class ActivityPollingService {
|
|
|
1760
1759
|
this.config = config;
|
|
1761
1760
|
this.pollConfig = {
|
|
1762
1761
|
interval: config.getActivityNexPollRequestMs(),
|
|
1763
|
-
attempts: config.getActivityRetry()
|
|
1764
|
-
backgroundPolling: true
|
|
1762
|
+
attempts: config.getActivityRetry()
|
|
1765
1763
|
};
|
|
1766
1764
|
this.batchCollectionDelayMs = config.getActivityBatchCollectionDelayMs();
|
|
1767
1765
|
this.maxRequestsPerBatch = config.getActivityMaxRequestPerBatch();
|
|
@@ -1778,17 +1776,19 @@ class ActivityPollingService {
|
|
|
1778
1776
|
subject.subscribe(done);
|
|
1779
1777
|
}
|
|
1780
1778
|
else {
|
|
1779
|
+
// Only the first pending request should start the batch collection timer.
|
|
1780
|
+
const wasEmpty = this.pendingRequests.size === 0;
|
|
1781
1781
|
subject = new Subject();
|
|
1782
1782
|
subject.subscribe(done);
|
|
1783
|
-
this.
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
this.
|
|
1790
|
-
})
|
|
1791
|
-
}
|
|
1783
|
+
this.addPendingRequest(caseId, subject);
|
|
1784
|
+
if (wasEmpty) {
|
|
1785
|
+
this.ngZone.runOutsideAngular(() => {
|
|
1786
|
+
this.currentTimeoutHandle = setTimeout(() => this.ngZone.run(() => {
|
|
1787
|
+
// console.log('timeout: flushing requests')
|
|
1788
|
+
this.flushRequests();
|
|
1789
|
+
}), this.batchCollectionDelayMs);
|
|
1790
|
+
});
|
|
1791
|
+
}
|
|
1792
1792
|
}
|
|
1793
1793
|
if (this.pendingRequests.size >= this.maxRequestsPerBatch) {
|
|
1794
1794
|
// console.log('max pending hit: flushing requests');
|
|
@@ -1806,6 +1806,9 @@ class ActivityPollingService {
|
|
|
1806
1806
|
clearTimeout(this.currentTimeoutHandle);
|
|
1807
1807
|
this.currentTimeoutHandle = undefined;
|
|
1808
1808
|
}
|
|
1809
|
+
if (!this.pendingRequests.size) {
|
|
1810
|
+
return;
|
|
1811
|
+
}
|
|
1809
1812
|
const requests = new Map(this.pendingRequests);
|
|
1810
1813
|
this.pendingRequests.clear();
|
|
1811
1814
|
this.performBatchRequest(requests);
|
|
@@ -1814,7 +1817,7 @@ class ActivityPollingService {
|
|
|
1814
1817
|
if (!this.isEnabled) {
|
|
1815
1818
|
return EMPTY;
|
|
1816
1819
|
}
|
|
1817
|
-
return polling(this.activityService.getActivities(...caseIds), this.pollConfig);
|
|
1820
|
+
return this.polling(this.activityService.getActivities(...caseIds), this.pollConfig);
|
|
1818
1821
|
}
|
|
1819
1822
|
postViewActivity(caseId) {
|
|
1820
1823
|
return this.postActivity(caseId, ActivityService.ACTIVITY_VIEW);
|
|
@@ -1827,17 +1830,20 @@ class ActivityPollingService {
|
|
|
1827
1830
|
// console.log('issuing batch request for cases: ' + caseIds);
|
|
1828
1831
|
this.ngZone.runOutsideAngular(() => {
|
|
1829
1832
|
// run polling outside angular zone so it does not trigger change detection
|
|
1830
|
-
this.pollActivitiesSubscription = this.pollActivities(caseIds).subscribe(
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1833
|
+
this.pollActivitiesSubscription = this.pollActivities(caseIds).subscribe({
|
|
1834
|
+
// process activity inside zone so it triggers change detection for activity.component.ts
|
|
1835
|
+
next: (activities) => this.ngZone.run(() => {
|
|
1836
|
+
activities.forEach((activity) => {
|
|
1837
|
+
// console.log('pushing activity: ' + activity.caseId);
|
|
1838
|
+
// Ignore activities returned for cases outside this local batch.
|
|
1839
|
+
requests.get(activity.caseId)?.next(activity);
|
|
1840
|
+
});
|
|
1841
|
+
}),
|
|
1842
|
+
error: (err) => this.ngZone.run(() => {
|
|
1843
|
+
console.log(`error: ${err}`);
|
|
1844
|
+
Array.from(requests.values()).forEach((subject) => subject.error(err));
|
|
1845
|
+
})
|
|
1846
|
+
});
|
|
1841
1847
|
});
|
|
1842
1848
|
}
|
|
1843
1849
|
postActivity(caseId, activityType) {
|
|
@@ -1848,7 +1854,42 @@ class ActivityPollingService {
|
|
|
1848
1854
|
...this.pollConfig,
|
|
1849
1855
|
interval: 5000 // inline with CCD Backend
|
|
1850
1856
|
};
|
|
1851
|
-
return polling(this.activityService.postActivity(caseId, activityType), pollingConfig);
|
|
1857
|
+
return this.polling(this.activityService.postActivity(caseId, activityType), pollingConfig);
|
|
1858
|
+
}
|
|
1859
|
+
addPendingRequest(caseId, subject) {
|
|
1860
|
+
this.pendingRequests.set(caseId, subject);
|
|
1861
|
+
// Components complete their returned Subject on destroy; remove it so a later same-case subscription gets a fresh Subject.
|
|
1862
|
+
subject.subscribe({
|
|
1863
|
+
complete: () => this.removePendingRequest(caseId, subject),
|
|
1864
|
+
error: () => this.removePendingRequest(caseId, subject)
|
|
1865
|
+
});
|
|
1866
|
+
}
|
|
1867
|
+
removePendingRequest(caseId, subject) {
|
|
1868
|
+
if (this.pendingRequests.get(caseId) !== subject) {
|
|
1869
|
+
return;
|
|
1870
|
+
}
|
|
1871
|
+
this.pendingRequests.delete(caseId);
|
|
1872
|
+
if (!this.pendingRequests.size && this.currentTimeoutHandle) {
|
|
1873
|
+
clearTimeout(this.currentTimeoutHandle);
|
|
1874
|
+
this.currentTimeoutHandle = undefined;
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
polling(request$, options) {
|
|
1878
|
+
const pollingOptions = {
|
|
1879
|
+
interval: options.interval,
|
|
1880
|
+
attempts: options.attempts ?? 9,
|
|
1881
|
+
exponentialUnit: options.exponentialUnit ?? 1000
|
|
1882
|
+
};
|
|
1883
|
+
return concat(request$, defer(() => timer(pollingOptions.interval).pipe(switchMap(() => request$))).pipe(repeat())).pipe(
|
|
1884
|
+
// Preserve consecutive-failure retry behaviour using the current RxJS retry config.
|
|
1885
|
+
retry({
|
|
1886
|
+
count: pollingOptions.attempts,
|
|
1887
|
+
delay: (_error, retryCount) => timer(this.getExponentialRetryDelay(retryCount, pollingOptions.exponentialUnit)),
|
|
1888
|
+
resetOnSuccess: true
|
|
1889
|
+
}));
|
|
1890
|
+
}
|
|
1891
|
+
getExponentialRetryDelay(consecutiveErrorsCount, exponentialUnit) {
|
|
1892
|
+
return Math.pow(2, consecutiveErrorsCount - 1) * exponentialUnit;
|
|
1852
1893
|
}
|
|
1853
1894
|
static ɵfac = function ActivityPollingService_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || ActivityPollingService)(i0.ɵɵinject(ActivityService), i0.ɵɵinject(i0.NgZone), i0.ɵɵinject(AbstractAppConfig)); };
|
|
1854
1895
|
static ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: ActivityPollingService, factory: ActivityPollingService.ɵfac });
|