当前位置: 首页>>代码示例>>Python>>正文


Python Variable.get方法代码示例

本文整理汇总了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) 
开发者ID:karpenkovarya,项目名称:airflow_for_beginners,代码行数:21,代码来源:utils.py

示例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) 
开发者ID:apache,项目名称:airflow,代码行数:21,代码来源:variable_command.py

示例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) 
开发者ID:airflow-plugins,项目名称:pandora-plugin,代码行数:23,代码来源:general_notification_hook.py

示例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) 
开发者ID:apache,项目名称:airflow,代码行数:9,代码来源:test_secrets.py

示例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")) 
开发者ID:apache,项目名称:airflow,代码行数:5,代码来源:test_variable.py

示例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)) 
开发者ID:apache,项目名称:airflow,代码行数:6,代码来源:test_variable.py

示例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')) 
开发者ID:apache,项目名称:airflow,代码行数:8,代码来源:test_variable.py

示例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)) 
开发者ID:apache,项目名称:airflow,代码行数:6,代码来源:test_variable.py

示例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)) 
开发者ID:apache,项目名称:airflow,代码行数:4,代码来源:test_variable.py

示例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)) 
开发者ID:apache,项目名称:airflow,代码行数:7,代码来源:test_variable.py

示例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)) 
开发者ID:apache,项目名称:airflow,代码行数:7,代码来源:test_variable.py

示例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)) 
开发者ID:apache,项目名称:airflow,代码行数:7,代码来源:test_variable.py

示例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)) 
开发者ID:apache,项目名称:airflow,代码行数:10,代码来源:test_variable.py

示例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") 
开发者ID:apache,项目名称:airflow,代码行数:8,代码来源:test_variable_command.py

示例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()) 
开发者ID:apache,项目名称:airflow,代码行数:9,代码来源:test_variable_command.py


注:本文中的airflow.models.Variable.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。