|
11 | 11 | specific language governing permissions and limitations under the License.
|
12 | 12 | """
|
13 | 13 |
|
| 14 | +import re |
| 15 | + |
14 | 16 | import jsonschema
|
15 | 17 | import ujson as json
|
16 | 18 | from apigw_manager.apigw.decorators import apigw_require
|
|
20 | 22 |
|
21 | 23 | import env
|
22 | 24 | from gcloud import err_code
|
23 |
| -from gcloud.apigw.decorators import ( |
24 |
| - mark_request_whether_is_trust, |
25 |
| - project_inject, |
26 |
| - return_json_response, |
27 |
| -) |
| 25 | +from gcloud.apigw.decorators import mark_request_whether_is_trust, project_inject, return_json_response |
28 | 26 | from gcloud.apigw.schemas import APIGW_CREATE_AND_START_TASK_PARAMS
|
29 | 27 | from gcloud.apigw.validators import CreateTaskValidator
|
30 | 28 | from gcloud.apigw.views.utils import logger
|
31 | 29 | from gcloud.common_template.models import CommonTemplate
|
32 | 30 | from gcloud.conf import settings
|
33 | 31 | from gcloud.constants import BUSINESS, COMMON, TaskCreateMethod
|
34 |
| -from gcloud.contrib.operate_record.constants import ( |
35 |
| - OperateSource, |
36 |
| - OperateType, |
37 |
| - RecordType, |
38 |
| -) |
| 32 | +from gcloud.contrib.operate_record.constants import OperateSource, OperateType, RecordType |
39 | 33 | from gcloud.contrib.operate_record.decorators import record_operation
|
40 | 34 | from gcloud.core.models import EngineConfig
|
41 | 35 | from gcloud.iam_auth.intercept import iam_intercept
|
42 | 36 | from gcloud.iam_auth.view_interceptors.apigw import CreateTaskInterceptor
|
43 | 37 | from gcloud.taskflow3.celery.tasks import prepare_and_start_task
|
44 | 38 | from gcloud.taskflow3.domains.auto_retry import AutoRetryNodeStrategyCreator
|
45 | 39 | from gcloud.taskflow3.domains.queues import PrepareAndStartTaskQueueResolver
|
46 |
| -from gcloud.taskflow3.models import TaskFlowInstance |
| 40 | +from gcloud.taskflow3.models import TaskCallBackRecord, TaskFlowInstance |
47 | 41 | from gcloud.tasktmpl3.models import TaskTemplate
|
48 | 42 | from gcloud.utils.decorators import request_validate
|
49 | 43 | from gcloud.utils.throttle import check_task_operation_throttle
|
@@ -77,6 +71,15 @@ def create_and_start_task(request, template_id, project_id):
|
77 | 71 | )
|
78 | 72 | )
|
79 | 73 |
|
| 74 | + callback_url = params.pop("callback_url", None) |
| 75 | + CALLBACK_URL_PATTERN = r"^https?://\w.+$" |
| 76 | + if callback_url and not (isinstance(callback_url, str) and re.match(CALLBACK_URL_PATTERN, callback_url)): |
| 77 | + return { |
| 78 | + "result": False, |
| 79 | + "code": err_code.REQUEST_PARAM_INVALID.code, |
| 80 | + "message": f"callback_url format error, must match {CALLBACK_URL_PATTERN}", |
| 81 | + } |
| 82 | + |
80 | 83 | # 根据template_id获取template
|
81 | 84 | if template_source == BUSINESS:
|
82 | 85 | try:
|
@@ -152,6 +155,11 @@ def create_and_start_task(request, template_id, project_id):
|
152 | 155 | )
|
153 | 156 | except Exception as e:
|
154 | 157 | return {"result": False, "message": str(e), "code": err_code.UNKNOWN_ERROR.code}
|
| 158 | + |
| 159 | + # create callback url record |
| 160 | + if callback_url: |
| 161 | + TaskCallBackRecord.objects.create(task_id=task.id, url=callback_url) |
| 162 | + |
155 | 163 | # 开始执行task
|
156 | 164 | queue, routing_key = PrepareAndStartTaskQueueResolver(
|
157 | 165 | settings.API_TASK_QUEUE_NAME_V2
|
|
0 commit comments