Skip to content

Commit

Permalink
allow responses of resources contain data but data is not an object (#69
Browse files Browse the repository at this point in the history
)

* allow responses of resources contain data but data is not an object


---------

Co-authored-by: zeyu10 <[email protected]>
  • Loading branch information
techloghub and zeyu10 authored Jun 14, 2024
1 parent 21feb20 commit 7d72d59
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,7 @@ public void updateUrlTypeResourceStatus(String executionId, String taskName, Str
ResourceStatus resourceStatus = getResourceStatus(executionId, taskName, resourceName);
resourceStatus.setUpdateTime(updateTime);

int retryIntervalSeconds = Optional.ofNullable(urlRet)
.map(it -> it.containsKey("data") ? it.getJSONObject("data") : it)
.map(it -> it.getJSONObject("sys_info"))
.map(it -> it.getInteger("retry_interval_seconds"))
.orElseGet(() -> Optional.ofNullable(urlRet)
.map(it -> it.getJSONObject("error_detail"))
.map(it -> it.getInteger("retry_interval_seconds"))
.orElse(0));
int retryIntervalSeconds = getRetryIntervalSeconds(urlRet);
if (retryIntervalSeconds > 0) {
resourceStatus.setResourceLimitedTime(updateTime + retryIntervalSeconds * 1000L);
log.info("update function url resource limit, executionId:{}, resourceName:{}, retryIntervalSeconds:{}",
Expand All @@ -197,6 +190,17 @@ public void updateUrlTypeResourceStatus(String executionId, String taskName, Str
}
}

private static int getRetryIntervalSeconds(JSONObject urlRet) {
return Optional.ofNullable(urlRet)
.map(it -> it.containsKey("data") && it.get("data") instanceof Map<?,?> ? it.getJSONObject("data") : it)
.map(it -> it.getJSONObject("sys_info"))
.map(it -> it.getInteger("retry_interval_seconds"))
.orElseGet(() -> Optional.ofNullable(urlRet)
.map(it -> it.getJSONObject("error_detail"))
.map(it -> it.getInteger("retry_interval_seconds"))
.orElse(0));
}

public void updateFlowTypeResourceStatus(String executionId, String taskName, String resourceName, DAG dag) {
try {
if (StringUtils.isBlank(taskName) || StringUtils.isBlank(resourceName)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.weibo.rill.flow.service.statistic

import com.alibaba.fastjson.JSONObject
import spock.lang.Specification
import spock.lang.Unroll

class DAGResourceStatisticTest extends Specification {
DAGResourceStatistic statistic = new DAGResourceStatistic()

@Unroll
def "test getRetryIntervalSeconds"() {
when:
JSONObject urlRet1 = new JSONObject(Map.of("data", "message"))
JSONObject urlRet2 = new JSONObject(Map.of("data", Map.of("sys_info", Map.of("retry_interval_seconds", 100))))
JSONObject urlRet3 = new JSONObject(Map.of("error_detail", Map.of("retry_interval_seconds", 100)))
then:
statistic.getRetryIntervalSeconds(urlRet1) == 0
statistic.getRetryIntervalSeconds(urlRet2) == 100
statistic.getRetryIntervalSeconds(urlRet3) == 100
}
}

0 comments on commit 7d72d59

Please sign in to comment.