Skip to content

Instantly share code, notes, and snippets.

@momota10s
Created September 21, 2021 02:23
Show Gist options
  • Save momota10s/8f4543c1e710a1f7b971cbd7473d76d7 to your computer and use it in GitHub Desktop.
Save momota10s/8f4543c1e710a1f7b971cbd7473d76d7 to your computer and use it in GitHub Desktop.
from airflow import DAG
from airflow.models import Variable
from airflow.utils.dates import days_ago
from airflow.contrib.operators.pubsub_operator import (
PubSubPublishOperator,
PubSubSubscriptionCreateOperator,
PubSubSubscriptionDeleteOperator,
PubSubTopicCreateOperator,
PubSubTopicDeleteOperator
)
from airflow.contrib.sensors.pubsub_sensor import PubSubPullSensor
PROJECT_ID = "your-project"
DAG_NAME = "sample-pubsub"
PUBSUB_MSG = {
'attributes': {"name": "momota"}
}
default_args = {
"start_date": days_ago(0),
}
with DAG(
DAG_NAME,
schedule_interval=None,
catchup=False,
default_args=default_args
) as dag:
task_exec_training_model = PubSubPublishOperator(
task_id="publish-task",
project=PROJECT_ID,
topic="test-topic",
messages=[PUBSUB_MSG],
create_topic=False,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment