Restart a data pipeline (Python SDK V2)
Updated at:
Calls RestartDataPipeline through OSS Python SDK V2 to restart a specified data pipeline (DataPipeline) rule so that it resumes processing the source data.
Prerequisites
-
OSS Python SDK V2 is installed. You can run
pip install alibabacloud-oss-v2to install it. -
Access credentials are configured by using environment variables. The example in this topic uses
EnvironmentVariableCredentialsProviderto read credentials from theOSS_ACCESS_KEY_IDandOSS_ACCESS_KEY_SECRETenvironment variables. -
DataPipeline operations are forwarded by OSS to the underlying workflow service. Make sure that the source general-purpose bucket and the destination vector bucket are located in the same region.
Sample code
import argparse
import alibabacloud_oss_v2 as oss
import alibabacloud_oss_v2.dataprocess as oss_dataprocess
parser = argparse.ArgumentParser(description="restart data pipeline sample")
parser.add_argument('--region', help='The region of the bucket.', required=True)
parser.add_argument('--endpoint', help='The endpoint of OSS.')
parser.add_argument('--data-pipeline-name', help='The name of the data pipeline.', required=True)
def main():
args = parser.parse_args()
credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()
cfg = oss.config.load_default()
cfg.credentials_provider = credentials_provider
cfg.region = args.region
if args.endpoint is not None:
cfg.endpoint = args.endpoint
client = oss_dataprocess.Client(cfg)
try:
result = client.restart_data_pipeline(
oss_dataprocess.models.RestartDataPipelineRequest(
data_pipeline_name=args.data_pipeline_name,
))
print(f'status code: {result.status_code}, request id: {result.request_id}')
except Exception as e:
print(f'error:\n{e}')
if __name__ == '__main__':
main()
Is this page helpful?