Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.4 kB
3
Indexable
Never
from airflow import DAG
from airflow.providers.bash.operators.bash import BashOperator
from airflow.providers.smtp.operators.smtp_operator import SmtpOperator
from airflow.utils.dates import days_ago

# DAG parameters
dag_id = 'cassandra_query_and_email_bash'
cassandra_query = "SELECT * FROM hos_event_recon_summary limit 10"
python_script_path = "/path/to/your/python_script.py"
recipient_email = 'veerendrakumar.meka@tcs.com'
smtp_server = '10.16.16.90'
smtp_port = 25

# Default arguments for tasks
default_args = {
    'owner': 'airflow',
    'start_date': days_ago(1),
    'retries': 2,
    'retry_delay': timedelta(minutes=1),
}

# Define the DAG
with DAG(dag_id, default_args=default_args) as dag:

    # Execute Python script to process Cassandra query and generate email content
    execute_script = BashOperator(
        task_id="execute_python_script",
        bash_command=f"python {python_script_path}",
    )

    # Send email with generated content
    send_email = SmtpOperator(
        task_id="send_email",
        filename="/tmp/email_content.html",  # Update this path to match the script's output
        mime_type="text/html",
        to=recipient_email,
        subject="Cassandra Query Results",
        smtp_server=smtp_server,
        smtp_port=smtp_port,
    )

    # Define task dependencies
    execute_script >> send_email
Leave a Comment