Skip to content

Commit

Permalink
feat: add polling to intacct location entity page (#906)
Browse files Browse the repository at this point in the history
  • Loading branch information
1 parent 21b824b commit 97e7066
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/app/core/services/si/si-core/si-workspace.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ export class SiWorkspaceService {

@Cacheable()
getWorkspace(orgId: string): Observable<IntacctWorkspace[]> {
return this.apiService.get('/workspaces/', {org_id: orgId});
return this.apiService.get('/workspaces/', {org_id: orgId, is_polling: false});
}

getWorkspaceWithoutCache(orgId: string, isPolling = false): Observable<IntacctWorkspace[]> {
return this.apiService.get('/workspaces/', {org_id: orgId, is_polling: isPolling});
}

postWorkspace(): Observable<IntacctWorkspace> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ import { LocationEntityPost } from 'src/app/core/models/intacct/intacct-configur
import { SiMappingsService } from 'src/app/core/services/si/si-core/si-mappings.service';
import { IntacctDestinationAttribute } from 'src/app/core/models/intacct/db/destination-attribute.model';
import { brandingConfig, brandingContent, brandingFeatureConfig, brandingKbArticles } from 'src/app/branding/branding-config';
import { interval, take } from 'rxjs';

/** Time (in ms) to wait before each request while polling for refresh dimensions status */
const DIMENSIONS_POLLING_INTERVAL = 3000;

/** Maximum time (in ms) to wait before terminating the poll for refresh dimensions status */
const DIMENSIONS_POLLING_TIMEOUT = 60_000;

@Component({
selector: 'app-intacct-location-entity',
Expand Down Expand Up @@ -124,10 +131,43 @@ export class IntacctLocationEntityComponent implements OnInit {

private handleSuccess(locationEntityMappingPayload: LocationEntityPost): void {
this.isRefreshDimensionInProgress = true;
this.mappingsService.refreshSageIntacctDimensions().subscribe(() => {
this.setOnboardingStateAndRedirect(locationEntityMappingPayload);
}, () => {
this.setOnboardingStateAndRedirect(locationEntityMappingPayload);

this.mappingsService.refreshSageIntacctDimensions().subscribe();
this.pollDimensionsSyncStatus({
onPollingComplete: () => {
this.setOnboardingStateAndRedirect(locationEntityMappingPayload);
}
});

}

/**
* Checks every `DIMENSIONS_POLLING_INTERVAL` ms whether dimensions have been refreshed
* for a maximum of `DIMENSIONS_POLLING_TIMEOUT` ms.
*
* Terminates either when dimensions have been refreshed, when refresh dimensions fails,
* or when polling times out - whichever occurs first.
*/
private pollDimensionsSyncStatus({onPollingComplete}: {onPollingComplete: () => void}) {
const ticks = Math.floor(DIMENSIONS_POLLING_TIMEOUT / DIMENSIONS_POLLING_INTERVAL);
const fyleOrgId = this.storageService.get('org').fyle_org_id;

const pollingSubscription = interval(DIMENSIONS_POLLING_INTERVAL).pipe(take(ticks)).subscribe(
{
next: (_tick) => {
this.workspaceService.getWorkspaceWithoutCache(fyleOrgId, true).subscribe(workspaces => {
const {destination_synced_at} = workspaces[0];

if (destination_synced_at !== null) {
onPollingComplete();
pollingSubscription.unsubscribe();
}
});
},

complete: () => {
onPollingComplete();
}
});
}

Expand Down

0 comments on commit 97e7066

Please sign in to comment.