Skip to content

Commit

Permalink
More changes to es dag
Browse files Browse the repository at this point in the history
  • Loading branch information
frankcash committed Aug 31, 2021
1 parent 9406cda commit cbd4380
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
22 changes: 8 additions & 14 deletions airflow_home/dags/elasticsearch_dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,13 @@
from datetime import datetime, timedelta


def my_custom_function(**kwargs):
def show_tables():
es = ElasticsearchHook(elasticsearch_conn_id='production-es')
es_conn = es.get_conn()
tables = es_conn.execute('SHOW TABLES')
for table, *_ in tables:
print(f"table: {table}")
rows = es_conn.execute(f'SELECT COUNT(*) FROM {table}')
print([row for row in rows])



return
with es.get_conn() as es_conn:
tables = es_conn.execute('SHOW TABLES')
for table, *_ in tables:
print(f"table: {table}")
return True


# Default settings applied to all tasks
Expand All @@ -40,7 +35,6 @@ def my_custom_function(**kwargs):


tn = PythonOperator(
task_id=f'python_print_date',
python_callable=my_custom_function,
op_kwargs={'task_number': 0},
task_id=f'es_print_tables',
python_callable=show_tables
)
2 changes: 1 addition & 1 deletion config/airflow.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ access_logfile = -
error_logfile = -

# Expose the configuration file in the web server
expose_config = False
expose_config = True

# Set to true to turn on authentication:
# https://airflow.incubator.apache.org/security.html#web-authentication
Expand Down

0 comments on commit cbd4380

Please sign in to comment.