本文整理汇总了Python中airflow.models.Variable.get方法的典型用法代码示例。如果您正苦于以下问题:Python Variable.get方法的具体用法?Python Variable.get怎么用?Python Variable.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类airflow.models.Variable
的用法示例。
在下文中一共展示了Variable.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render_template
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import get [as 别名]
def render_template(**context):
""" Render HTML template using questions metadata from S3 bucket """
hook = S3Hook(aws_conn_id="s3_connection")
file_content = hook.read_key(
key=S3_FILE_NAME, bucket_name=Variable.get("S3_BUCKET")
)
questions = json.loads(file_content)
root = os.path.dirname(os.path.abspath(__file__))
env = Environment(loader=FileSystemLoader(root))
template = env.get_template("email_template.html")
html_content = template.render(questions=questions)
# Push rendered HTML as a string to the Airflow metadata database
# to make it available for the next task
task_instance = context["task_instance"]
task_instance.xcom_push(key="html_content", value=html_content)
示例2: variables_get
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import get [as 别名]
def variables_get(args):
"""Displays variable by a given name"""
try:
if args.default is None:
var = Variable.get(
args.key,
deserialize_json=args.json
)
print(var)
else:
var = Variable.get(
args.key,
deserialize_json=args.json,
default_var=args.default
)
print(var)
except (ValueError, KeyError) as e:
print(str(e), file=sys.stderr)
sys.exit(1)
示例3: create_slack_message
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import get [as 别名]
def create_slack_message(state):
"""
:param state: State of dagrun such as 'Success' or 'Failure' etc.
:return: Standard body content for the slack message
"""
jinja_confs = {
'dagid': '{{ dag.dag_id }}',
'date': "{{ macros.ds_format(ts, '%Y-%m-%dT%H:%M:%S', '%x %I:%M:%S %p') }}",
'url_date': "{{ macros.ds_format(ts, '%Y-%m-%dT%H:%M:%S', '%Y-%m-%d+%H%%3A%M%%3A%S') }}",
'taskid': '{{ task.task_id }}',
'owner': "{{ conf.get('operators', 'default_owner') }}",
'url': "{{ conf.get('webserver', 'base_url') }}"
}
if state.lower() == 'failure':
msg = 'DAG *{dagid}* for {date} has *failed* task {taskid} on the {owner} instance. Current task failures: ' \
'<{url}/admin/taskinstance/?flt0_dag_id_equals={dagid}&flt1_state_equals=failed' \
'&flt4_execution_date_equals={url_date}| Task Instances.>'
if state.lower() == 'success':
msg = 'DAG *{dagid}* has successfully processed {date} on the {owner} instance. <{url}/admin/airflow/gantt?' \
'dag_id={dagid}&execution_date={url_date}|Gantt chart.>'
return msg.format(**jinja_confs)
示例4: test_backend_fallback_to_default_var
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import get [as 别名]
def test_backend_fallback_to_default_var(self):
"""
Test if a default_var is defined and no backend has the Variable,
the value returned is default_var
"""
variable_value = Variable.get(key="test_var", default_var="new")
self.assertEqual("new", variable_value)
示例5: test_variable_set_get_round_trip
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import get [as 别名]
def test_variable_set_get_round_trip(self):
Variable.set("tested_var_set_id", "Monday morning breakfast")
self.assertEqual("Monday morning breakfast", Variable.get("tested_var_set_id"))
示例6: test_variable_set_get_round_trip_json
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import get [as 别名]
def test_variable_set_get_round_trip_json(self):
value = {"a": 17, "b": 47}
Variable.set("tested_var_set_id", value, serialize_json=True)
self.assertEqual(value, Variable.get("tested_var_set_id", deserialize_json=True))
示例7: test_variable_set_existing_value_to_blank
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import get [as 别名]
def test_variable_set_existing_value_to_blank(self):
test_value = 'Some value'
test_key = 'test_key'
Variable.set(test_key, test_value)
Variable.set(test_key, '')
self.assertEqual('', Variable.get('test_key'))
示例8: test_get_non_existing_var_should_return_default
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import get [as 别名]
def test_get_non_existing_var_should_return_default(self):
default_value = "some default val"
self.assertEqual(default_value, Variable.get("thisIdDoesNotExist",
default_var=default_value))
示例9: test_get_non_existing_var_with_none_default_should_return_none
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import get [as 别名]
def test_get_non_existing_var_with_none_default_should_return_none(self):
self.assertIsNone(Variable.get("thisIdDoesNotExist", default_var=None))
示例10: test_get_non_existing_var_should_not_deserialize_json_default
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import get [as 别名]
def test_get_non_existing_var_should_not_deserialize_json_default(self):
default_value = "}{ this is a non JSON default }{"
self.assertEqual(default_value, Variable.get("thisIdDoesNotExist",
default_var=default_value,
deserialize_json=True))
示例11: test_variable_setdefault_round_trip
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import get [as 别名]
def test_variable_setdefault_round_trip(self):
key = "tested_var_setdefault_1_id"
value = "Monday morning breakfast in Paris"
Variable.setdefault(key, value)
self.assertEqual(value, Variable.get(key))
示例12: test_variable_setdefault_round_trip_json
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import get [as 别名]
def test_variable_setdefault_round_trip_json(self):
key = "tested_var_setdefault_2_id"
value = {"city": 'Paris', "Happiness": True}
Variable.setdefault(key, value, deserialize_json=True)
self.assertEqual(value, Variable.get(key, deserialize_json=True))
示例13: test_variable_setdefault_existing_json
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import get [as 别名]
def test_variable_setdefault_existing_json(self):
key = "tested_var_setdefault_2_id"
value = {"city": 'Paris', "Happiness": True}
Variable.set(key, value, serialize_json=True)
val = Variable.setdefault(key, value, deserialize_json=True)
# Check the returned value, and the stored value are handled correctly.
self.assertEqual(value, val)
self.assertEqual(value, Variable.get(key, deserialize_json=True))
示例14: test_variables_set
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import get [as 别名]
def test_variables_set(self):
"""Test variable_set command"""
variable_command.variables_set(self.parser.parse_args([
'variables', 'set', 'foo', 'bar']))
self.assertIsNotNone(Variable.get("foo"))
self.assertRaises(KeyError, Variable.get, "foo1")
示例15: test_variables_get
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import get [as 别名]
def test_variables_get(self):
Variable.set('foo', {'foo': 'bar'}, serialize_json=True)
with redirect_stdout(io.StringIO()) as stdout:
variable_command.variables_get(self.parser.parse_args([
'variables', 'get', 'foo']))
self.assertEqual('{\n "foo": "bar"\n}\n', stdout.getvalue())