From 4cec1e7ecd5ad74594707aeef4160e756bac0bba Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 20 Sep 2018 13:21:23 -0400 Subject: [PATCH] LP#1779158 Add support for vandelay session trackers Use session tracker polling for enqueue and import processes instead of watching the streamed results. Signed-off-by: Bill Erickson --- .../src/app/staff/cat/vandelay/import.component.ts | 92 ++++++++++++++-------- .../src/app/staff/cat/vandelay/queue.component.ts | 2 +- .../src/app/staff/cat/vandelay/vandelay.service.ts | 27 +++++++ 3 files changed, 87 insertions(+), 34 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/import.component.ts b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/import.component.ts index 925b28d64d..928a691eb0 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/import.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/import.component.ts @@ -15,6 +15,7 @@ import {ProgressInlineComponent} from '@eg/share/dialog/progress-inline.componen import {Subject} from 'rxjs/Subject'; interface ImportOptions { + session_key: string; overlay_map?: {[qrId: number]: /* breId */ number}; import_no_match?: boolean; auto_overlay_exact?: boolean; @@ -24,6 +25,7 @@ interface ImportOptions { merge_profile?: any; fall_through_merge_profile?: any; strip_field_groups?: number[]; + exit_early: boolean; } @Component({ @@ -365,26 +367,35 @@ export class ImportComponent implements OnInit, AfterViewInit, OnDestroy { const method = `open-ils.vandelay.${this.recordType}.process_spool`; - return this.net.request( - 'open-ils.vandelay', method, - this.auth.token(), this.sessionKey, this.activeQueueId, - null, null, this.selectedBibSource - ).pipe(tap( - resp => { - const e = this.evt.parse(resp); - if (e) { - console.log(e); - return; + return new Promise((resolve, reject) => { + this.net.request( + 'open-ils.vandelay', method, + this.auth.token(), this.sessionKey, this.activeQueueId, + null, null, this.selectedBibSource, null, true + ).subscribe( + tracker => { + const e = this.evt.parse(tracker); + if (e) { console.error(e); return reject(); } + + // Spooling is in progress, track the results. + this.vandelay.pollSessionTracker(tracker.id()) + .subscribe( + trkr => { + this.enqueueProgress.update({ + // enqueue API only tracks actions performed + max: null, + value: trkr.actions_performed() + }); + }, + err => { console.log(err); reject(); }, + () => { + this.enqueueProgress.update({max: 1, value: 1}); + resolve(); + } + ); } - - // the enqeueu process currently only returns the - // number of items processed. - this.enqueueProgress.update({max: null, value: resp}); - }, - err => {}, - () => this.enqueueProgress.update({max: 1, value: 1}) - - )).toPromise(); + ); + }); } importRecords(): Promise { @@ -414,24 +425,38 @@ export class ImportComponent implements OnInit, AfterViewInit, OnDestroy { target = recIds; } - return this.net.request('open-ils.vandelay', - method, this.auth.token(), target, options - ).pipe(tap( - resp => { - const e = this.evt.parse(resp); - if (e) { console.log(e); return; } - - this.importProgress.update( - {max: resp.total, value: resp.progress}); - }, - err => {}, - () => this.importProgress.update({max: 1, value: 1}) - )).toPromise(); + return new Promise((resolve, reject) => { + this.net.request('open-ils.vandelay', + method, this.auth.token(), target, options) + .subscribe( + tracker => { + const e = this.evt.parse(tracker); + if (e) { console.error(e); return reject(); } + + // Spooling is in progress, track the results. + this.vandelay.pollSessionTracker(tracker.id()) + .subscribe( + trkr => { + this.importProgress.update({ + max: trkr.total_actions(), + value: trkr.actions_performed() + }); + }, + err => { console.log(err); reject(); }, + () => { + this.importProgress.update({max: 1, value: 1}); + resolve(); + } + ); + } + ); + }); } compileImportOptions(): ImportOptions { const options: ImportOptions = { + session_key: this.sessionKey, import_no_match: this.importNonMatching, auto_overlay_exact: this.mergeOnExact, auto_overlay_best_match: this.mergeOnBestMatch, @@ -439,7 +464,8 @@ export class ImportComponent implements OnInit, AfterViewInit, OnDestroy { opp_acq_copy_overlay: this.autoOverlayAcqCopies, merge_profile: this.selectedMergeProfile, fall_through_merge_profile: this.selectedFallThruMergeProfile, - strip_field_groups: this.selectedTrashGroups + strip_field_groups: this.selectedTrashGroups, + exit_early: true }; if (this.vandelay.importSelection) { diff --git a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/queue.component.ts b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/queue.component.ts index e8b3747979..a6f67c34d1 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/queue.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/queue.component.ts @@ -117,7 +117,7 @@ export class QueueComponent implements OnInit, AfterViewInit { // Reapply the grid configuration now that we've // dynamically added columns. - this.queueGrid.context.applyColumnsConfig(); + this.queueGrid.context.applyGridConfig(); } ); } diff --git a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/vandelay.service.ts b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/vandelay.service.ts index 375a84107a..7a6d6405e4 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/vandelay.service.ts +++ b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/vandelay.service.ts @@ -312,5 +312,32 @@ export class VandelayService { ); } + // Poll every 2 seconds for session tracker updates so long + // as the session tracker is active. + // Returns an Observable of tracker objects. + pollSessionTracker(id: number): Observable { + return new Observable(observer => { + this.getNextSessionTracker(id, observer); + }); + } + + getNextSessionTracker(id: number, observer: any) { + + // No need for this to be an authoritative call. + // It will complete eventually regardless. + this.pcrud.retrieve('vst', id).subscribe( + tracker => { + if (tracker && tracker.state() === 'active') { + observer.next(tracker); + setTimeout(() => + this.getNextSessionTracker(id, observer), 2000); + } else { + console.debug( + `Vandelay session tracker ${id} is ${tracker.state()}`); + observer.complete(); + } + } + ); + } } -- 2.11.0