UI: Add parse persistent RPC status for send RPC command
This commit is contained in:
parent
90c84f84d0
commit
ec2e097229
@ -69,27 +69,11 @@ public class RpcV2Controller extends AbstractRpcController {
|
|||||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
||||||
@RequestMapping(value = "/persistent/{rpcId}", method = RequestMethod.GET)
|
@RequestMapping(value = "/persistent/{rpcId}", method = RequestMethod.GET)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public ResponseEntity<Rpc> getPersistedRpc(@PathVariable("rpcId") String strRpc) throws ThingsboardException {
|
public Rpc getPersistedRpc(@PathVariable("rpcId") String strRpc) throws ThingsboardException {
|
||||||
checkParameter("RpcId", strRpc);
|
checkParameter("RpcId", strRpc);
|
||||||
try {
|
try {
|
||||||
RpcId rpcId = new RpcId(UUID.fromString(strRpc));
|
RpcId rpcId = new RpcId(UUID.fromString(strRpc));
|
||||||
Rpc rpc = checkRpcId(rpcId, Operation.READ);
|
return checkRpcId(rpcId, Operation.READ);
|
||||||
HttpStatus status;
|
|
||||||
switch (rpc.getStatus()) {
|
|
||||||
case FAILED:
|
|
||||||
status = HttpStatus.BAD_GATEWAY;
|
|
||||||
break;
|
|
||||||
case TIMEOUT:
|
|
||||||
status = HttpStatus.GATEWAY_TIMEOUT;
|
|
||||||
break;
|
|
||||||
case QUEUED:
|
|
||||||
case DELIVERED:
|
|
||||||
status = HttpStatus.ACCEPTED;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
status = HttpStatus.OK;
|
|
||||||
}
|
|
||||||
return new ResponseEntity<>(rpc, status);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw handleException(e);
|
throw handleException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,7 +35,7 @@ import {
|
|||||||
LegendKeyData,
|
LegendKeyData,
|
||||||
widgetType
|
widgetType
|
||||||
} from '@app/shared/models/widget.models';
|
} from '@app/shared/models/widget.models';
|
||||||
import { HttpErrorResponse, HttpResponse } from '@angular/common/http';
|
import { HttpErrorResponse } from '@angular/common/http';
|
||||||
import {
|
import {
|
||||||
calculateIntervalStartEndTime,
|
calculateIntervalStartEndTime,
|
||||||
calculateTsOffset,
|
calculateTsOffset,
|
||||||
@ -69,7 +69,7 @@ import {
|
|||||||
} from '@shared/models/query/query.models';
|
} from '@shared/models/query/query.models';
|
||||||
import { filter, map, switchMap, takeUntil } from 'rxjs/operators';
|
import { filter, map, switchMap, takeUntil } from 'rxjs/operators';
|
||||||
import { AlarmDataListener } from '@core/api/alarm-data.service';
|
import { AlarmDataListener } from '@core/api/alarm-data.service';
|
||||||
import { PersistentRpc } from '@shared/models/rpc.models';
|
import { RpcStatus } from '@shared/models/rpc.models';
|
||||||
|
|
||||||
const moment = moment_;
|
const moment = moment_;
|
||||||
|
|
||||||
@ -710,8 +710,17 @@ export class WidgetSubscription implements IWidgetSubscription {
|
|||||||
if (persistent && persistentPollingInterval > 0) {
|
if (persistent && persistentPollingInterval > 0) {
|
||||||
return timer(persistentPollingInterval / 2, persistentPollingInterval).pipe(
|
return timer(persistentPollingInterval / 2, persistentPollingInterval).pipe(
|
||||||
switchMap(() => this.ctx.deviceService.getPersistedRpc(response.rpcId, true)),
|
switchMap(() => this.ctx.deviceService.getPersistedRpc(response.rpcId, true)),
|
||||||
filter((persistentResponse: HttpResponse<PersistentRpc>) => persistentResponse.status !== 202),
|
filter(persistentRespons =>
|
||||||
map(persistentResponse => persistentResponse.body.response),
|
persistentRespons.status !== RpcStatus.DELIVERED && persistentRespons.status !== RpcStatus.QUEUED),
|
||||||
|
switchMap(persistentResponse => {
|
||||||
|
if (persistentResponse.status === RpcStatus.TIMEOUT) {
|
||||||
|
return throwError({status: 504});
|
||||||
|
} else if (persistentResponse.status === RpcStatus.FAILED) {
|
||||||
|
return throwError({status: 502, statusText: persistentResponse.response.error});
|
||||||
|
} else {
|
||||||
|
return of(persistentResponse.response);
|
||||||
|
}
|
||||||
|
}),
|
||||||
takeUntil(rpcSubject)
|
takeUntil(rpcSubject)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { defaultHttpOptionsFromConfig, RequestConfig } from './http-utils';
|
import { defaultHttpOptionsFromConfig, RequestConfig } from './http-utils';
|
||||||
import { Observable, ReplaySubject } from 'rxjs';
|
import { Observable, ReplaySubject } from 'rxjs';
|
||||||
import { HttpClient, HttpResponse } from '@angular/common/http';
|
import { HttpClient } from '@angular/common/http';
|
||||||
import { PageLink } from '@shared/models/page/page-link';
|
import { PageLink } from '@shared/models/page/page-link';
|
||||||
import { PageData } from '@shared/models/page/page-data';
|
import { PageData } from '@shared/models/page/page-data';
|
||||||
import {
|
import {
|
||||||
@ -138,12 +138,8 @@ export class DeviceService {
|
|||||||
return this.http.post<Device>(`/api/rpc/twoway/${deviceId}`, requestBody, defaultHttpOptionsFromConfig(config));
|
return this.http.post<Device>(`/api/rpc/twoway/${deviceId}`, requestBody, defaultHttpOptionsFromConfig(config));
|
||||||
}
|
}
|
||||||
|
|
||||||
public getPersistedRpc(rpcId: string, fullResponse = false,
|
public getPersistedRpc(rpcId: string, fullResponse = false, config?: RequestConfig): Observable<PersistentRpc> {
|
||||||
config?: RequestConfig): Observable<PersistentRpc | HttpResponse<PersistentRpc>> {
|
return this.http.get<PersistentRpc>(`/api/rpc/persistent/${rpcId}`, defaultHttpOptionsFromConfig(config));
|
||||||
return this.http.get<PersistentRpc>(`/api/rpc/persistent/${rpcId}`, {
|
|
||||||
...defaultHttpOptionsFromConfig(config),
|
|
||||||
observe: fullResponse ? 'response' : undefined
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public findByQuery(query: DeviceSearchQuery,
|
public findByQuery(query: DeviceSearchQuery,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user