#
# 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())
#
# 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())