-
Notifications
You must be signed in to change notification settings - Fork 548
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support callback header #1808
Merged
Merged
Support callback header #1808
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ import org.apache.spark.sql.mlsql.session.{MLSQLSparkSession, SparkSessionCacheM | |
import org.apache.spark.{MLSQLConf, SparkInstanceService} | ||
import tech.mlsql.MLSQLEnvKey | ||
import tech.mlsql.app.{CustomController, ResultResp} | ||
import tech.mlsql.common.JsonUtils | ||
import tech.mlsql.common.utils.log.Logging | ||
import tech.mlsql.common.utils.serder.json.JSONTool | ||
import tech.mlsql.crawler.RestUtils | ||
|
@@ -105,6 +106,7 @@ class RestController extends ApplicationController with WowLog with Logging { | |
new Parameter(name = "sessionPerRequest", required = false, description = "by default false", `type` = "boolean", allowEmptyValue = false), | ||
new Parameter(name = "async", required = false, description = "If set true ,please also provide a callback url use `callback` parameter and the job will run in background and the API will return. default: false", `type` = "boolean", allowEmptyValue = false), | ||
new Parameter(name = "callback", required = false, description = "Used when async is set true. callback is a url. default: false", `type` = "string", allowEmptyValue = false), | ||
new Parameter(name = "callbackHeader", required = false, description = "Provide a jsonString parameter to set the header parameter of the callback request. default: false", `type` = "string", allowEmptyValue = false), | ||
new Parameter(name = "maxRetries", required = false, description = "Max retries of request callback.", `type` = "int", allowEmptyValue = false), | ||
new Parameter(name = "skipInclude", required = false, description = "disable include statement. default: false", `type` = "boolean", allowEmptyValue = false), | ||
new Parameter(name = "skipAuth", required = false, description = "disable table authorize . default: true", `type` = "boolean", allowEmptyValue = false), | ||
|
@@ -147,6 +149,12 @@ class RestController extends ApplicationController with WowLog with Logging { | |
if (paramAsBoolean("async", false)) { | ||
JobManager.asyncRun(sparkSession, jobInfo, () => { | ||
val urlString = param("callback") | ||
val callbackHeaderString = param("callbackHeader") | ||
var callbackHeader = Map[String,String]() | ||
if (callbackHeaderString != null && callbackHeaderString.nonEmpty){ | ||
callbackHeader = JsonUtils.fromJson[Map[String,String]](callbackHeaderString) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里fromJson异常的情况是要block run/script的接口流程吗? 还是要catch住,留个容错模式 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 应该抛出,callbackHeader设置的不对会影响后续的callback |
||
} | ||
|
||
val maxTries = Math.max(0, paramAsInt("maxRetries", -1)) + 1 | ||
try { | ||
ScriptSQLExec.parse(param("sql"), context, | ||
|
@@ -161,7 +169,8 @@ class RestController extends ApplicationController with WowLog with Logging { | |
RestUtils.httpClientPost(urlString, | ||
Map("stat" -> s"""succeeded""", | ||
"res" -> outputResult, | ||
"jobInfo" -> JSONTool.toJsonStr(jobInfo))), | ||
"jobInfo" -> JSONTool.toJsonStr(jobInfo)), | ||
callbackHeader), | ||
HttpStatus.SC_OK == _.getStatusLine.getStatusCode, | ||
response => logger.error(s"Succeeded SQL callback request failed after ${maxTries} attempts, " + | ||
s"the last response status is: ${response.getStatusLine.getStatusCode}.") | ||
|
@@ -178,7 +187,8 @@ class RestController extends ApplicationController with WowLog with Logging { | |
RestUtils.httpClientPost(urlString, | ||
Map("stat" -> s"""failed""", | ||
"msg" -> (e.getMessage + "\n" + msgBuffer.mkString("\n")), | ||
"jobInfo" -> JSONTool.toJsonStr(jobInfo))), | ||
"jobInfo" -> JSONTool.toJsonStr(jobInfo)), | ||
callbackHeader), | ||
HttpStatus.SC_OK == _.getStatusLine.getStatusCode, | ||
response => logger.error(s"Fail SQL callback request failed after ${maxTries} attempts, " + | ||
s"the last response status is: ${response.getStatusLine.getStatusCode}.") | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR comment 带上issue 号吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是说commit吗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment里面有带