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')")
|
||||
@RequestMapping(value = "/persistent/{rpcId}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public ResponseEntity<Rpc> getPersistedRpc(@PathVariable("rpcId") String strRpc) throws ThingsboardException {
|
||||
public Rpc getPersistedRpc(@PathVariable("rpcId") String strRpc) throws ThingsboardException {
|
||||
checkParameter("RpcId", strRpc);
|
||||
try {
|
||||
RpcId rpcId = new RpcId(UUID.fromString(strRpc));
|
||||
Rpc rpc = 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);
|
||||
return checkRpcId(rpcId, Operation.READ);
|
||||
} catch (Exception e) {
|
||||
throw handleException(e);
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ import {
|
||||
LegendKeyData,
|
||||
widgetType
|
||||
} from '@app/shared/models/widget.models';
|
||||
import { HttpErrorResponse, HttpResponse } from '@angular/common/http';
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
import {
|
||||
calculateIntervalStartEndTime,
|
||||
calculateTsOffset,
|
||||
@ -69,7 +69,7 @@ import {
|
||||
} from '@shared/models/query/query.models';
|
||||
import { filter, map, switchMap, takeUntil } from 'rxjs/operators';
|
||||
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_;
|
||||
|
||||
@ -710,8 +710,17 @@ export class WidgetSubscription implements IWidgetSubscription {
|
||||
if (persistent && persistentPollingInterval > 0) {
|
||||
return timer(persistentPollingInterval / 2, persistentPollingInterval).pipe(
|
||||
switchMap(() => this.ctx.deviceService.getPersistedRpc(response.rpcId, true)),
|
||||
filter((persistentResponse: HttpResponse<PersistentRpc>) => persistentResponse.status !== 202),
|
||||
map(persistentResponse => persistentResponse.body.response),
|
||||
filter(persistentRespons =>
|
||||
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)
|
||||
);
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { defaultHttpOptionsFromConfig, RequestConfig } from './http-utils';
|
||||
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 { PageData } from '@shared/models/page/page-data';
|
||||
import {
|
||||
@ -138,12 +138,8 @@ export class DeviceService {
|
||||
return this.http.post<Device>(`/api/rpc/twoway/${deviceId}`, requestBody, defaultHttpOptionsFromConfig(config));
|
||||
}
|
||||
|
||||
public getPersistedRpc(rpcId: string, fullResponse = false,
|
||||
config?: RequestConfig): Observable<PersistentRpc | HttpResponse<PersistentRpc>> {
|
||||
return this.http.get<PersistentRpc>(`/api/rpc/persistent/${rpcId}`, {
|
||||
...defaultHttpOptionsFromConfig(config),
|
||||
observe: fullResponse ? 'response' : undefined
|
||||
});
|
||||
public getPersistedRpc(rpcId: string, fullResponse = false, config?: RequestConfig): Observable<PersistentRpc> {
|
||||
return this.http.get<PersistentRpc>(`/api/rpc/persistent/${rpcId}`, defaultHttpOptionsFromConfig(config));
|
||||
}
|
||||
|
||||
public findByQuery(query: DeviceSearchQuery,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user