Skip to content

Commit

Permalink
Migrate Google calendar example DAG to new design AIP-47 (#24333)
Browse files Browse the repository at this point in the history
related: #22447
  • Loading branch information
chenglongyan committed Jun 12, 2022
1 parent 2e8bd9d commit 6eb60f8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Upload data from Google Calendar to GCS
To upload data from Google Calendar to Google Cloud Storage you can use the
:class:`~airflow.providers.google.cloud.transfers.calendar_to_gcs.GoogleCalendarToGCSOperator`.

.. exampleinclude:: /../../airflow/providers/google/cloud/example_dags/example_calendar_to_gcs.py
.. exampleinclude:: /../../tests/system/providers/google/calendar/example_calendar_to_gcs.py
:language: python
:dedent: 4
:start-after: [START upload_calendar_to_gcs]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,58 @@
from datetime import datetime

from airflow import models
from airflow.providers.google.cloud.operators.gcs import GCSCreateBucketOperator, GCSDeleteBucketOperator
from airflow.providers.google.cloud.transfers.calendar_to_gcs import GoogleCalendarToGCSOperator
from airflow.utils.trigger_rule import TriggerRule

BUCKET = os.environ.get("GCP_GCS_BUCKET", "test28397yeo")
ENV_ID = os.environ.get("SYSTEM_TESTS_ENV_ID")
PROJECT_ID = os.environ.get("SYSTEM_TESTS_GCP_PROJECT")
DAG_ID = "example_calendar_to_gcs"

BUCKET_NAME = f"bucket_{DAG_ID}_{ENV_ID}"
CALENDAR_ID = os.environ.get("CALENDAR_ID", "1234567890qwerty")
API_VERSION = "v3"

with models.DAG(
"example_calendar_to_gcs",
DAG_ID,
schedule_interval='@once', # Override to match your needs
start_date=datetime(2022, 1, 1),
start_date=datetime(2021, 1, 1),
catchup=False,
tags=["example"],
tags=["example", "calendar"],
) as dag:
create_bucket = GCSCreateBucketOperator(
task_id="create_bucket", bucket_name=BUCKET_NAME, project_id=PROJECT_ID
)

# [START upload_calendar_to_gcs]
upload_calendar_to_gcs = GoogleCalendarToGCSOperator(
task_id="upload_calendar_to_gcs",
destination_bucket=BUCKET,
destination_bucket=BUCKET_NAME,
calendar_id=CALENDAR_ID,
api_version=API_VERSION,
)
# [END upload_calendar_to_gcs]

delete_bucket = GCSDeleteBucketOperator(
task_id="delete_bucket", bucket_name=BUCKET_NAME, trigger_rule=TriggerRule.ALL_DONE
)

(
# TEST SETUP
create_bucket
# TEST BODY
>> upload_calendar_to_gcs
# TEST TEARDOWN
>> delete_bucket
)

from tests.system.utils.watcher import watcher

# This test needs watcher in order to properly mark success/failure
# when "tearDown" task with trigger rule is part of the DAG
list(dag.tasks) >> watcher()

from tests.system.utils import get_test_run # noqa: E402

# Needed to run the example DAG with pytest (see: tests/system/README.md#run_via_pytest)
test_run = get_test_run(dag)

0 comments on commit 6eb60f8

Please sign in to comment.