管道是任务的队列。当您提交异步任务后,任务会进入管道中进行排队,根据优先级和提交顺序依次被调度执行。本文提供了Python SDK管道相关功能的API调用示例,包含添加管道、更新管道、删除管道、查询管道。
搜索管道
可以直接通过SearchPipeline接口搜索管道信息。
import os
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkcore.auth.credentials import AccessKeyCredential
from aliyunsdkmts.request.v20140618.SearchPipelineRequest import SearchPipelineRequest
# 读取环境变量中设置的ACCESS_KEY ACCESS_KEY_SECRET信息
credentials = AccessKeyCredential(os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'], os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET'])
# region_id 为调用的服务地域ID,支持的地域参考 https://help.aliyun.com/document_detail/43248.html
client = AcsClient(region_id = 'cn-shanghai', credential = credentials)
request = SearchPipelineRequest()
request.set_accept_format('json')
response = client.do_action_with_exception(request);
# 输出打印
print(str(response, encoding='utf-8'))
查询管道
如果已经知道pipelineId,可以通过pipelineId调用QueryPipelineList接口查询管道信息。
import os
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkcore.auth.credentials import AccessKeyCredential
from aliyunsdkmts.request.v20140618.QueryPipelineListRequest import QueryPipelineListRequest
# 读取环境变量中设置的ACCESS_KEY ACCESS_KEY_SECRET信息
credentials = AccessKeyCredential(os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'], os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET'])
# region_id 为调用的服务地域ID,支持的地域参考 https://help.aliyun.com/document_detail/43248.html
client = AcsClient(region_id = 'cn-shanghai', credential = credentials)
request = QueryPipelineListRequest()
request.set_PipelineIds('9bad380c3d2cc4df9c6****')
request.set_accept_format('json')
response = client.do_action_with_exception(request);
# 输出打印
print(str(response, encoding='utf-8'))
更新管道
通过UpdatePipeline更新管道信息,包括更新管道名称,状态。管道的状态包括Active、Paused。
import os
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkcore.auth.credentials import AccessKeyCredential
from aliyunsdkmts.request.v20140618.UpdatePipelineRequest import UpdatePipelineRequest
# 读取环境变量中设置的ACCESS_KEY ACCESS_KEY_SECRET信息
credentials = AccessKeyCredential(os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'], os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET'])
# region_id 为调用的服务地域ID,支持的地域参考 https://help.aliyun.com/document_detail/43248.html
client = AcsClient(region_id = 'cn-shanghai', credential = credentials)
request = UpdatePipelineRequest()
request.set_PipelineId('91c22c4df9c6****')
request.set_Name('update name')
request.set_State('Active')
response = client.do_action_with_exception(request);
# 输出打印
print(str(response, encoding='utf-8'))
相关文档
文档内容是否对您有帮助?