#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
from airflow.models.dag import DAG
from airflow.utils import timezone
from airflow.contrib.jobs.event_handlers import AIFlowHandler
from airflow.operators.bash import BashOperator
default_args = {'start_date': timezone.utcnow(), 'schedule_interval': '@once'}
dag = DAG(dag_id='workflow_1', default_args=default_args)
op_0 = BashOperator(task_id='0-job-name',
                    dag=dag,
                    bash_command='echo "0 hello word!"')
op_1 = BashOperator(task_id='1-job-name',
                    dag=dag,
                    bash_command='echo "1 hello word!"')
op_2 = BashOperator(task_id='2-job-name',
                    dag=dag,
                    bash_command='echo "2 hello word!"')
op_0.subscribe_event('key_1', 'UNDEFINED', 'default', '')
configs_op_0 = '[{"__af_object_type__": "jsonable", "__class__": "MetConfig", "__module__": "ai_flow.graph.edge", "action": "START", "condition": "NECESSARY", "event_key": "key_1", "event_type": "UNDEFINED", "event_value": "value_1", "life": "ONCE", "namespace": "default", "sender": "*", "value_condition": "EQUAL"}]'

op_0.set_events_handler(AIFlowHandler(configs_op_0))
op_2.subscribe_event('key_2', 'UNDEFINED', 'default', '1-job-name')
configs_op_2 = '[{"__af_object_type__": "jsonable", "__class__": "MetConfig", "__module__": "ai_flow.graph.edge", "action": "START", "condition": "NECESSARY", "event_key": "key_2", "event_type": "UNDEFINED", "event_value": "value_2", "life": "ONCE", "namespace": "default", "sender": "1-job-name", "value_condition": "EQUAL"}]'

op_2.set_events_handler(AIFlowHandler(configs_op_2))
from datetime import datetime

from airflow.models.dag import DAG
from airflow.operators.bash import BashOperator
from tests.dags.test_event_handler import TaskStatusChangedEventHandler

default_args = {'schedule_interval': '@once', 'start_date': datetime.utcnow()}

dag = DAG(dag_id='schedule_on_state', default_args=default_args)

op_0 = BashOperator(task_id='task_1', dag=dag, bash_command="echo hello")

op_1 = BashOperator(task_id='task_2', dag=dag, bash_command="echo hello")
op_1.subscribe_event('schedule_on_state.task_1', 'TASK_STATUS_CHANGED',
                     'schedule_on_state', 'task_1')
op_1.set_events_handler(TaskStatusChangedEventHandler())
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
from datetime import datetime, timedelta
from airflow.operators.bash import BashOperator
from airflow.contrib.jobs.event_handlers import StartEventHandler

from airflow import DAG

DEFAULT_DATE = datetime(2016, 1, 1)
dag = DAG(dag_id="single",
          start_date=datetime.utcnow(),
          schedule_interval='@once')

op1 = BashOperator(task_id="task_1",
                   dag=dag,
                   owner='airflow',
                   bash_command='echo "hello world!"')
op1.executor_config = {'periodic_config': {'interval': {'seconds': 20}}}
op1.subscribe_event('UNREACHED_EVENT', 'UNREACHED_EVENT', 'UNREACHED_EVENT')
op1.set_events_handler(StartEventHandler())
Пример #4
0
    schedule_interval='@once'
)

t1 = BashOperator(
    task_id='print_date',
    bash_command='date',
    dag=dag,
)

t2 = BashOperator(
    task_id='sleep_1000_secs',
    bash_command='sleep 100',
    dag=dag,
    event_handler=ActionEventHandler()
)
t2.subscribe_event('start', '', event_namespace='test_namespace', from_task_id='print_date')
t2.subscribe_event(event_key="stop",
                   event_namespace='test_namespace',
                   event_type=UNDEFINED_EVENT_TYPE)


t4 = BashOperator(
    task_id='sleep_to_be_stopped',
    bash_command='sleep 100',
    dag=dag,
    event_handler=ActionEventHandler()
)


def my_sleeping_function(random_base):
    """This is a function that will run within the DAG execution"""
Пример #5
0
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
from datetime import datetime, timedelta
from airflow.operators.bash import BashOperator
from airflow.contrib.jobs.event_handlers import StartEventHandler
from airflow import DAG

dag = DAG(dag_id="trigger_task",
          start_date=datetime.utcnow() + timedelta(1),
          schedule_interval='@once')

op1 = BashOperator(task_id="task_1",
                   dag=dag,
                   owner='airflow',
                   bash_command='echo "hello world 1!"')

op2 = BashOperator(task_id="task_2",
                   dag=dag,
                   owner='airflow',
                   bash_command='echo "hello world 2!"')
op2.subscribe_event('key_1')
op2.set_events_handler(StartEventHandler())
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
from datetime import datetime, timedelta
from airflow.operators.bash import BashOperator
from airflow.contrib.jobs.event_handlers import StartEventHandler
from airflow import DAG

dag = DAG(dag_id="trigger_task",
          start_date=datetime.utcnow() + timedelta(1),
          schedule_interval='@once')

op1 = BashOperator(task_id="task_1",
                   dag=dag,
                   owner='airflow',
                   bash_command='echo "hello world 1!"')

op2 = BashOperator(task_id="task_2",
                   dag=dag,
                   owner='airflow',
                   bash_command='echo "hello world 2!"')
op2.subscribe_event(event_key='key_1', from_task_id='task_1')
op2.set_events_handler(StartEventHandler())
Пример #7
0
dag = DAG(dag_id='event_based_scheduler_dag',
          start_date=timezone.utcnow(),
          schedule_interval='@once')

t1 = BashOperator(
    task_id='print_date',
    bash_command='date',
    dag=dag,
)

t2 = BashOperator(task_id='sleep_1000_secs',
                  bash_command='sleep 100',
                  dag=dag,
                  event_handler=ActionEventHandler())
t2.subscribe_event('start', '', event_namespace='test_namespace')
t2.subscribe_event(event_key="stop",
                   event_namespace='test_namespace',
                   event_type=UNDEFINED_EVENT_TYPE)

t4 = BashOperator(task_id='sleep_to_be_stopped',
                  bash_command='sleep 100',
                  dag=dag,
                  event_handler=ActionEventHandler())


def my_sleeping_function(random_base):
    """This is a function that will run within the DAG execution"""
    time.sleep(random_base)

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
from datetime import datetime, timedelta
from airflow.operators.bash import BashOperator
from airflow.contrib.jobs.event_handlers import RestartEventHandler

from airflow import DAG

DEFAULT_DATE = datetime(2016, 1, 1)
dag = DAG(dag_id="single", start_date=datetime.utcnow(), schedule_interval='@once')

op1 = BashOperator(task_id="task_1", dag=dag,  owner='airflow', bash_command='sleep 10')
op1.subscribe_event(event_key='a', event_namespace='test_namespace')
op1.set_events_handler(RestartEventHandler())
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
from datetime import datetime
from airflow.operators.bash import BashOperator
from airflow.contrib.jobs.event_handlers import ActionEventHandler

from airflow import DAG

DEFAULT_DATE = datetime(2016, 1, 1)
dag = DAG(dag_id="event_dag",
          start_date=datetime.utcnow(),
          schedule_interval='@once')

op1 = BashOperator(task_id="task_1",
                   dag=dag,
                   owner='airflow',
                   bash_command='echo "hello world 1!"')

op2 = BashOperator(task_id="task_2",
                   dag=dag,
                   owner='airflow',
                   bash_command='echo "hello world 2!"')

op2.subscribe_event('start', '', '')
op2.set_events_handler(ActionEventHandler())
Пример #10
0
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
from airflow.models.dag import DAG
from airflow.utils import timezone
from airflow.contrib.jobs.event_handlers import AIFlowHandler
from airflow.operators.bash import BashOperator

dag = DAG(dag_id='workflow_1',
          start_date=timezone.utcnow(),
          schedule_interval='@once')
op_0 = BashOperator(task_id='0_job',
                    dag=dag,
                    bash_command='echo "0 hello word!"')
op_1 = BashOperator(task_id='1_job',
                    dag=dag,
                    bash_command='echo "1 hello word!"')
op_2 = BashOperator(task_id='2_job',
                    dag=dag,
                    bash_command='echo "2 hello word!"')
op_1.subscribe_event('key_1', 'UNDEFINED', 'default')
configs_op_1 = '[{"__af_object_type__": "jsonable", "__class__": "MetConfig", "__module__": "ai_flow.graph.edge", "action": "START", "condition": "NECESSARY", "event_key": "key_1", "event_type": "UNDEFINED", "event_value": "value_1", "life": "ONCE", "namespace": "default", "value_condition": "EQUAL"}]'

op_1.set_events_handler(AIFlowHandler(configs_op_1))
op_2.subscribe_event('key_2', 'UNDEFINED', 'default')
configs_op_2 = '[{"__af_object_type__": "jsonable", "__class__": "MetConfig", "__module__": "ai_flow.graph.edge", "action": "START", "condition": "NECESSARY", "event_key": "key_2", "event_type": "UNDEFINED", "event_value": "value_2", "life": "ONCE", "namespace": "default", "value_condition": "EQUAL"}]'

op_2.set_events_handler(AIFlowHandler(configs_op_2))