下发条件任务成功,但满足条件后任务并不执行
已完成在demo的web页面上提交条件任务,设定好执行起止时间,电量要求,发起任务成功,通过thing/product/{DOCK-SN}/events主题监听时间,在达到条件时,可以正常监听到flighttask_ready事件:
{"bid":"05857bc8-ed08-4934-9b76-67120bcdf943","data":{"flight_ids":["b3e8c6d7-28fc-46c4-9fe5-46897fe5d65e"]},"method":"flighttask_ready","tid":"5e44fbd4-5e6e-429d-9c9e-cc812d6ca1d1","timestamp":1729129322985,"gateway":"机场的SN"}
但是任务并没有执行。飞机没有任何反应。
在后端的代码里面,测试发现,在prepareFlightTask那里,flighttaskPrepare也都执行成功了,这是什么原因呢?有没有人遇到过这个情况?
TopicServicesResponse<ServicesReplyData> serviceReply = abstractWaylineService.flighttaskPrepare(
SDKManager.getDeviceSDK(waylineJob.getDockSn()), flightTask);
-
flighttask_ready 事件触发后,后端demo的代码能正常进入 flighttaskReady 函数,里面有flighttask_execute执行的地方,如下:
@Override
public TopicEventsResponse<MqttReply> flighttaskReady(TopicEventsRequest<FlighttaskReady> response, MessageHeaders headers) {
List<String> flightIds = response.getData().getFlightIds();
log.info("ready task list:{}", Arrays.toString(flightIds.toArray()) );
// Check conditional task blocking status.
String blockedId = waylineRedisService.getBlockedWaylineJobId(response.getGateway());
System.out.println(response.toString());
System.out.println(blockedId);
if (!StringUtils.hasText(blockedId)) {
return null;
}
Optional<DeviceDTO> deviceOpt = deviceRedisService.getDeviceOnline(response.getGateway());
if (deviceOpt.isEmpty()) {
return null;
}
DeviceDTO device = deviceOpt.get();
try {
for (String jobId : flightIds) {
boolean isExecute = this.executeFlightTask(device.getWorkspaceId(), jobId);
if (!isExecute) {
return null;
}
Optional<WaylineJobDTO> waylineJobOpt = waylineRedisService.getConditionalWaylineJob(jobId);
if (waylineJobOpt.isEmpty()) {
log.info("The conditional job has expired and will no longer be executed.");
return new TopicEventsResponse<>();
}
WaylineJobDTO waylineJob = waylineJobOpt.get();
this.retryPrepareJob(new ConditionalWaylineJobKey(device.getWorkspaceId(), response.getGateway(), jobId), waylineJob);
return new TopicEventsResponse<>();
}
} catch (Exception e) {
log.error("Failed to execute conditional task.");
e.printStackTrace();
}
return new TopicEventsResponse<>();
}String blockedId = waylineRedisService.getBlockedWaylineJobId(response.getGateway());
这一句获取的blockedId 始终为空,传进来的response是正常有值的,如下:TopicRequestsRequest{method='flighttask_ready', gateway='机场SN', from='机场SN', needReply=false, tid='ddd8627c-c2b5-4f06-a156-476ccf7718a3', bid='4aa56d27-0020-4d12-b645-f5322641ce82', timestamp=1729162622555, data=FlighttaskReady{flightIds=[3b875e12-b334-4f40-b70b-8e45c1f6134d]}}
这个blockId是什么啊?我在redis里面查这个key:"wayline_job_block", 查出来也是null
请先登录再写评论。
评论
7 条评论