Last active
June 3, 2020 12:29
-
-
Save addomafi/f494774fdad80e82bc4dc577dfa09bec to your computer and use it in GitHub Desktop.
Script to trigger an dag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from airflow.api.common.experimental.trigger_dag import trigger_dag | |
from airflow.utils import timezone | |
import json, sys, datetime, six | |
if __name__ == '__main__': | |
trigger_dag_id = sys.argv[1] | |
execution_date = sys.argv[2] | |
if isinstance(execution_date, datetime.datetime): | |
execution_date = execution_date.isoformat() | |
elif isinstance(execution_date, six.string_types): | |
execution_date = execution_date | |
elif execution_date is None: | |
execution_date = execution_date | |
else: | |
raise TypeError( | |
'Expected str or datetime.datetime type ' | |
'for execution_date. Got {}'.format( | |
type(execution_date))) | |
if execution_date is not None: | |
run_id = 'trig__{}'.format(execution_date) | |
execution_date = timezone.parse(execution_date) | |
else: | |
run_id = 'trig__' + timezone.utcnow().isoformat() | |
trigger_dag(dag_id=trigger_dag_id, | |
run_id=run_id, | |
conf=json.dumps(None), | |
execution_date=execution_date, | |
replace_microseconds=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment