當前位置: 首頁>>代碼示例>>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: 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)
開發者ID:cjquinon,項目名稱:incubator-airflow,代碼行數:34,代碼來源:cli.py

示例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')
開發者ID:VViles,項目名稱:airflow_test,代碼行數:10,代碼來源:tuto2.py

示例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)
開發者ID:caiqingqing1990,項目名稱:istio,代碼行數:17,代碼來源:istio_common_dag.py

示例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)
開發者ID:yogesh2021,項目名稱:airflow,代碼行數:17,代碼來源:cli.py

示例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()
開發者ID:CityOfPhiladelphia,項目名稱:phl-airflow,代碼行數:17,代碼來源:slack_notify_plugin.py

示例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()
開發者ID:CityOfPhiladelphia,項目名稱:phl-airflow,代碼行數:38,代碼來源:error_notifications_plugin.py

示例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)
開發者ID:moritzpein,項目名稱:airflow,代碼行數:6,代碼來源:core.py

示例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")
開發者ID:moritzpein,項目名稱:airflow,代碼行數:5,代碼來源:core.py

示例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
開發者ID:veggiemonk,項目名稱:istio,代碼行數:88,代碼來源:istio_common_dag.py

示例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
開發者ID:veggiemonk,項目名稱:istio,代碼行數:7,代碼來源:istio_common_dag.py

示例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
開發者ID:KaiwenWang,項目名稱:sofa-mesh,代碼行數:7,代碼來源:istio_common_dag.py

示例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]')
開發者ID:VViles,項目名稱:airflow_test,代碼行數:8,代碼來源:tuto2.py

示例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')
開發者ID:VViles,項目名稱:airflow_test,代碼行數:8,代碼來源:tuto2.py

示例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
開發者ID:dkyos,項目名稱:dev-samples,代碼行數:33,代碼來源:project-workflow.py

示例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)
開發者ID:moritzpein,項目名稱:airflow,代碼行數:6,代碼來源:core.py


注:本文中的airflow.models.Variable.get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。