當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。