| 1 |
# Copyright (C) 2013 Yahoo! Inc. All Rights Reserved. |
| 2 |
# |
| 3 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 |
# not use this file except in compliance with the License. You may obtain |
| 5 |
# a copy of the License at |
| 6 |
# |
| 7 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
# |
| 9 |
# Unless required by applicable law or agreed to in writing, software |
| 10 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 |
# License for the specific language governing permissions and limitations |
| 13 |
# under the License. |
| 14 |
|
| 15 |
import os |
| 16 |
|
| 17 |
from taskflow.patterns import linear_flow as lf |
| 18 |
from taskflow import task |
| 19 |
|
| 20 |
|
| 21 |
class UnfortunateTask(task.Task): |
| 22 |
def execute(self): |
| 23 |
print('executing %s' % self) |
| 24 |
boom = os.environ.get('BOOM') |
| 25 |
if boom: |
| 26 |
print('> Critical error: boom = %s' % boom) |
| 27 |
raise SystemExit() |
| 28 |
else: |
| 29 |
print('> this time not exiting') |
| 30 |
|
| 31 |
|
| 32 |
class TestTask(task.Task): |
| 33 |
def execute(self): |
| 34 |
print('executing %s' % self) |
| 35 |
|
| 36 |
|
| 37 |
def flow_factory(): |
| 38 |
return lf.Flow('example').add( |
| 39 |
TestTask(name='first'), |
| 40 |
UnfortunateTask(name='boom'), |
| 41 |
TestTask(name='second')) |