turbaszek commented on a change in pull request #13366: URL: https://github.com/apache/airflow/pull/13366#discussion_r564572069
########## File path: airflow/providers/google/cloud/example_dags/example_workflows.py ########## @@ -0,0 +1,192 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import os + +from airflow import DAG +from airflow.providers.google.cloud.operators.workflows import ( + WorkflowsCancelExecutionOperator, + WorkflowsCreateExecutionOperator, + WorkflowsCreateWorkflowOperator, + WorkflowsDeleteWorkflowOperator, + WorkflowsGetExecutionOperator, + WorkflowsGetWorkflowOperator, + WorkflowsListExecutionsOperator, + WorkflowsListWorkflowsOperator, + WorkflowsUpdateWorkflowOperator, +) +from airflow.providers.google.cloud.sensors.workflows import WorkflowExecutionSensor +from airflow.utils.dates import days_ago + +LOCATION = os.environ.get("GCP_LOCATION", "us-central1") +PROJECT_ID = os.environ.get("GCP_PROJECT_ID", "an-id") + +WORKFLOW_ID = "airflow-test-workflow" + +# [START how_to_define_workflow] +WORKFLOW_CONTENT = """ +- getCurrentTime: + call: http.get + args: + url: https://us-central1-workflowsample.cloudfunctions.net/datetime + result: currentTime +- readWikipedia: + call: http.get + args: + url: https://en.wikipedia.org/w/api.php + query: + action: opensearch + search: ${currentTime.body.dayOfTheWeek} + result: wikiResult +- returnResult: + return: ${wikiResult.body[1]} +""" + +WORKFLOW = { + "description": "Test workflow", + "labels": {"airflow-version": "dev"}, + "source_contents": WORKFLOW_CONTENT, +} +# [START how_to_define_workflow] + +EXECUTION = {"argument": ""} + +SLEEP_WORKFLOW_ID = "sleep_workflow" +SLEEP_WORKFLOW_CONTENT = """ +- someSleep: + call: sys.sleep + args: + seconds: 120 +""" + +SLEEP_WORKFLOW = { + "description": "Test workflow", + "labels": {"airflow-version": "dev"}, + "source_contents": SLEEP_WORKFLOW_CONTENT, +} +# [START how_to_define_workflow] + + +with DAG("example_cloud_workflows", start_date=days_ago(1), schedule_interval=None) as dag: + # [START how_to_create_workflow] + create_workflow = WorkflowsCreateWorkflowOperator( + task_id="create_workflow", + location=LOCATION, + project_id=PROJECT_ID, + workflow=WORKFLOW, + workflow_id=WORKFLOW_ID, + ) + # [END how_to_create_workflow] + + # [START how_to_update_workflows] + update_workflows = WorkflowsUpdateWorkflowOperator( Review comment: Added 👌 ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
