本文整理汇总了Python中airflow.models.Variable.get方法的典型用法代码示例。如果您正苦于以下问题:Python Variable.get方法的具体用法?Python Variable.get怎么用?Python Variable.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类airflow.models.Variable
的用法示例。
在下文中一共展示了Variable.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: variables
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import get [as 别名]
def variables(args):
if args.get:
try:
var = Variable.get(args.get,
deserialize_json=args.json,
default_var=args.default)
print(var)
except ValueError as e:
print(e)
if args.delete:
session = settings.Session()
session.query(Variable).filter_by(key=args.delete).delete()
session.commit()
session.close()
if args.set:
Variable.set(args.set[0], args.set[1])
# Work around 'import' as a reserved keyword
imp = getattr(args, 'import')
if imp:
if os.path.exists(imp):
import_helper(imp)
else:
print("Missing variables file.")
if args.export:
export_helper(args.export)
if not (args.set or args.get or imp or args.export or args.delete):
# list all variables
session = settings.Session()
vars = session.query(Variable)
msg = "\n".join(var.key for var in vars)
print(msg)
示例2: set_sms
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import get [as 别名]
def set_sms(*args, **context):
group = Variable.get('group')
if group == 'night_shift':
context['task_instance'].xcom_push('recipient', '0011223344')
context['task_instance'].xcom_push('message', 'night airflow message')
else:
context['task_instance'].xcom_push('recipient', '0011223344')
context['task_instance'].xcom_push('message', 'day airflow message')
示例3: ReportDailySuccessful
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import get [as 别名]
def ReportDailySuccessful(task_instance, **kwargs):
date = kwargs['execution_date']
latest_run = float(Variable.get('latest_daily_timestamp'))
timestamp = time.mktime(date.timetuple())
logging.info('Current run\'s timestamp: %s \n'
'latest_daily\'s timestamp: %s', timestamp, latest_run)
if timestamp >= latest_run:
Variable.set('latest_daily_timestamp', timestamp)
run_sha = task_instance.xcom_pull(task_ids='get_git_commit')
latest_version = GetSettingPython(task_instance, 'VERSION')
logging.info('setting latest green daily to: %s', run_sha)
Variable.set('latest_sha', run_sha)
Variable.set('latest_daily', latest_version)
logging.info('latest_sha test to %s', run_sha)
示例4: variables
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import get [as 别名]
def variables(args):
if args.get:
try:
var = Variable.get(args.get, deserialize_json=args.json, default_var=args.default)
print(var)
except ValueError as e:
print(e)
if args.set:
Variable.set(args.set[0], args.set[1])
if not args.set and not args.get:
# list all variables
session = settings.Session()
vars = session.query(Variable)
msg = "\n".join(var.key for var in vars)
print(msg)
示例5: failed
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import get [as 别名]
def failed(self, context):
self.conf = context["conf"]
self.task = context["task"]
self.execution_date = context["execution_date"]
self.dag = context["dag"]
self.errors = SlackAPIPostOperator(
task_id='task_failed',
token=Variable.get('slack_token'),
channel='C1SRU2R33',
text="Your DAG has encountered an error, please follow the link to view the log details: " + "http://localhost:8080/admin/airflow/log?" + "task_id=" + task.task_id + "&" +\
"execution_date=" + execution_date.isoformat() + "&" + "dag_id=" + dag.dag_id,
dag=pipeline
)
errors.execute()
示例6: wrapped
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import get [as 别名]
def wrapped(context):
"""ping error in slack on failure and provide link to the log"""
conf = context["conf"]
task = context["task"]
execution_date = context["execution_date"]
dag = context["dag"]
base_url = conf.get('webserver', 'base_url')
# Get the ID of the target slack channel
slack_token = Variable.get(slack_token_variable)
sc = SlackClient(slack_token)
response = sc.api_call('channels.list')
for channel in response['channels']:
if channel['name'].lower() == channel_name.lower():
break
else:
raise AirflowException('No channel named {} found.'.format(channel_name))
# Construct a slack operator to send the message off.
notifier = cls(
task_id='task_failed',
token=slack_token,
channel=channel['id'],
text=(
"Your DAG has encountered an error, please follow the link "
"to view the log details: "
"{}/admin/airflow/log?"
"task_id={}&"
"dag_id={}&"
"execution_date={}"
).format(base_url, task.task_id, dag.dag_id,
execution_date.isoformat()),
dag=dag,
)
notifier.execute()
示例7: 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)
assert value == Variable.get("tested_var_set_id", deserialize_json=True)
示例8: 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")
assert "Monday morning breakfast" == Variable.get("tested_var_set_id")
示例9: GenerateTestArgs
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import get [as 别名]
def GenerateTestArgs(**kwargs):
"""Loads the configuration that will be used for this Iteration."""
conf = kwargs['dag_run'].conf
if conf is None:
conf = dict()
""" Airflow gives the execution date when the job is supposed to be run,
however we dont backfill and only need to run one build therefore use
the current date instead of the date that is passed in """
# date = kwargs['execution_date']
date = datetime.datetime.now()
timestamp = time.mktime(date.timetuple())
# Monthly releases started in Nov 2017 with 0.3.0, so minor is # of months
# from Aug 2017.
minor_version = (date.year - 2017) * 12 + (date.month - 1) - 7
major_version = AirflowGetVariableOrBaseCase('major_version', 0)
# This code gets information about the latest released version so we know
# What version number to use for this round.
r_minor = int(AirflowGetVariableOrBaseCase('released_version_minor', 0))
r_patch = int(AirflowGetVariableOrBaseCase('released_version_patch', 0))
# If we have already released a monthy for this mounth then bump
# The patch number for the remander of the month.
if r_minor == minor_version:
patch = r_patch + 1
else:
patch = 0
# If version is overriden then we should use it otherwise we use it's
# default or monthly value.
version = conf.get('VERSION')
if monthly and not version:
version = '{}.{}.{}'.format(major_version, minor_version, patch)
default_conf = environment_config.get_airflow_config(
version,
timestamp,
major=major_version,
minor=minor_version,
patch=patch,
date=date.strftime('%Y%m%d'),
rc=date.strftime('%H-%M'))
config_settings = dict(VERSION=default_conf['VERSION'])
config_settings_name = [
'PROJECT_ID',
'MFEST_URL',
'MFEST_FILE',
'GCS_STAGING_BUCKET',
'SVC_ACCT',
'GITHUB_ORG',
'GITHUB_REPO',
'GCS_GITHUB_PATH',
'TOKEN_FILE',
'GCR_STAGING_DEST',
'GCR_RELEASE_DEST',
'GCS_MONTHLY_RELEASE_PATH',
'DOCKER_HUB',
'GCS_BUILD_BUCKET',
'RELEASE_PROJECT_ID',
]
for name in config_settings_name:
config_settings[name] = conf.get(name) or default_conf[name]
if monthly:
config_settings['MFEST_COMMIT'] = conf.get(
'MFEST_COMMIT') or Variable.get('latest_sha')
gcs_path = conf.get('GCS_MONTHLY_STAGE_PATH')
if not gcs_path:
gcs_path = default_conf['GCS_MONTHLY_STAGE_PATH']
else:
config_settings['MFEST_COMMIT'] = conf.get(
'MFEST_COMMIT') or default_conf['MFEST_COMMIT']
gcs_path = conf.get('GCS_DAILY_PATH') or default_conf['GCS_DAILY_PATH']
config_settings['GCS_STAGING_PATH'] = gcs_path
config_settings['GCS_BUILD_PATH'] = '{}/{}'.format(
config_settings['GCS_BUILD_BUCKET'], gcs_path)
config_settings['GCS_RELEASE_TOOLS_PATH'] = '{}/release-tools/{}'.format(
config_settings['GCS_BUILD_BUCKET'], gcs_path)
config_settings['GCS_FULL_STAGING_PATH'] = '{}/{}'.format(
config_settings['GCS_STAGING_BUCKET'], gcs_path)
config_settings['ISTIO_REPO'] = 'https://github.com/{}/{}.git'.format(
config_settings['GITHUB_ORG'], config_settings['GITHUB_REPO'])
return config_settings
示例10: AirflowGetVariableOrBaseCase
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import get [as 别名]
def AirflowGetVariableOrBaseCase(var, base):
try:
return Variable.get(var)
except KeyError:
return base
示例11: GetVariableOrDefault
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import get [as 别名]
def GetVariableOrDefault(var, default):
try:
return Variable.get(var)
except KeyError:
return default
示例12: set_mail
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import get [as 别名]
def set_mail(*args, **context):
group = Variable.get('group')
if group == 'night_shift':
context['task_instance'].xcom_push(key='recipient', value='[email protected]')
else:
context['task_instance'].xcom_push(key='recipient', value='[email protected]')
示例13: set_call
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import get [as 别名]
def set_call(*args, **context):
group = Variable.get('group')
if group == 'night_shift':
context['task_instance'].xcom_push(key='recipient', value='0011223344')
else:
context['task_instance'].xcom_push(key='recipient', value='0011223344')
示例14: DAG
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import get [as 别名]
from airflow import DAG
from airflow.operators.bash_operator import BashOperator
from airflow.operators.dummy_operator import DummyOperator
from airflow.operators.python_operator import PythonOperator
from datetime import datetime,timedelta
from airflow.models import Variable
SRC=Variable.get("SRC")
#SRC='./'
COUNTRY=Variable.get("COUNTRY")
#COUNTRY='PL'
dag = DAG('project-workflow',description='Project Workflow DAG',
schedule_interval = '*/5 0 * * *',
start_date=datetime(2017,7,1),
catchup=False)
xlsx_to_csv_task = BashOperator(
task_id='xlsx_to_csv',
bash_command='"$src"/test.sh "$country" 2nd_param_xlsx',
env={'src': SRC, 'country': COUNTRY},
dag=dag)
merge_command = SRC + '/test.sh ' + COUNTRY + ' 2nd_param_merge'
merge_task = BashOperator(
task_id='merge',
bash_command=merge_command ,
dag=dag)
my_templated_command = """
{{ params.src }}/test.sh {{ params.country}} 2nd_param_cleansing
示例15: 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"
assert default_value == Variable.get("thisIdDoesNotExist",
default_var=default_value)