-
Notifications
You must be signed in to change notification settings - Fork 54
快速开始
韩数 edited this page Nov 7, 2023
·
6 revisions
$ pip install bamboo-pipeline
由于 bamboo-pipeline
运行时基于 Django 实现,所以需要新建一个 Django 项目:
$ django-admin startproject bamboo_engine_playground
$ cd bamboo_engine_playground
在 bamboo_engine_playground.settings.py
下添加如下配置:
from pipeline.eri.celery.queues import *
from celery import Celery
app = Celery("proj")
app.config_from_object("django.conf:settings")
INSTALLED_APPS = [
...
"pipeline.component_framework",
"pipeline.eri",
...
]
其他可安装的 INSTALLED_APPS:
INSTALLED_APPS = [
...
"pipeline.component_framework",
"pipeline.variable_framework", # 变量框架
"pipeline.engine",
"pipeline.log", # 日志
"pipeline.contrib.statistics", # 统计
"pipeline.contrib.periodic_task", # 周期任务
"pipeline.contrib.external_plugins", # 远程插件
"pipeline.contrib.engine_admin", # 引擎管理端
"pipeline.django_signal_valve", # 信号
"pipeline.eri",
...
]
在 bamboo_engine_playground
目录下初始化数据库:
$ python manage.py migrate
首先在 bamboo_engine_playground
目录下启动 celery worker:
$ DJANGO_SETTINGS_MODULE=bamboo_engine_playground.settings celery worker -A bamboo_engine_playground.settings -Q er_execute,er_schedule -l info
创建并执行一个简单的流程:
import time
from bamboo_engine import api
from bamboo_engine.builder import *
from pipeline.eri.runtime import BambooDjangoRuntime
# 使用 builder 构造出流程描述结构
start = EmptyStartEvent()
# 这里先使用 bamboo-pipeline 自带的示例组件,我们会在后续的章节中学习如何自定义组件
act = ServiceActivity(component_code="example_component")
end = EmptyEndEvent()
start.extend(act).extend(end)
pipeline = builder.build_tree(start)
# 执行流程对象
runtime = BambooDjangoRuntime()
# 如果需要忽略流程中的环检查,可以指定为True cycle_tolerate
# api.run_pipeline(runtime=runtime, pipeline=pipeline, cycle_tolerate=True)
api.run_pipeline(runtime=runtime, pipeline=pipeline)
# 等待 1s 后获取流程执行结果
time.sleep(1)
result = api.get_pipeline_states(runtime=runtime, root_id=pipeline["id"])
print(result.data)
随后我们就能够看到流程的状态信息,如下所示,流程中的所有节点已经执行成功:
{'pc31c89e6b85a4e2c8c5db477978c1a57': {'id': 'pc31c89e6b85a4e2c8c5db477978c1a57',
'state': 'FINISHED',
'root_id:': 'pc31c89e6b85a4e2c8c5db477978c1a57',
'parent_id': 'pc31c89e6b85a4e2c8c5db477978c1a57',
'version': 'vaf47e56f2f31401e979c3c47b2a0c285',
'loop': 1,
'retry': 0,
'skip': False,
'created_time': datetime.datetime(2021, 3, 10, 3, 45, 54, 688664, tzinfo=<UTC>),
'started_time': datetime.datetime(2021, 3, 10, 3, 45, 54, 688423, tzinfo=<UTC>),
'archived_time': datetime.datetime(2021, 3, 10, 3, 45, 54, 775165, tzinfo=<UTC>),
'children': {'e42035b3f98374062921a191115fc602e': {'id': 'e42035b3f98374062921a191115fc602e',
'state': 'FINISHED',
'root_id:': 'pc31c89e6b85a4e2c8c5db477978c1a57',
'parent_id': 'pc31c89e6b85a4e2c8c5db477978c1a57',
'version': 've2d0fa10d7d842a1bcac25984620232a',
'loop': 1,
'retry': 0,
'skip': False,
'created_time': datetime.datetime(2021, 3, 10, 3, 45, 54, 744490, tzinfo=<UTC>),
'started_time': datetime.datetime(2021, 3, 10, 3, 45, 54, 744308, tzinfo=<UTC>),
'archived_time': datetime.datetime(2021, 3, 10, 3, 45, 54, 746690, tzinfo=<UTC>)},
'e327f83de42df4ebfab375c271bf63d29': {'id': 'e327f83de42df4ebfab375c271bf63d29',
'state': 'FINISHED',
'root_id:': 'pc31c89e6b85a4e2c8c5db477978c1a57',
'parent_id': 'pc31c89e6b85a4e2c8c5db477978c1a57',
'version': 'v893cdc14150d4df5b20f2db32ba142b3',
'loop': 1,
'retry': 0,
'skip': False,
'created_time': datetime.datetime(2021, 3, 10, 3, 45, 54, 753321, tzinfo=<UTC>),
'started_time': datetime.datetime(2021, 3, 10, 3, 45, 54, 753122, tzinfo=<UTC>),
'archived_time': datetime.datetime(2021, 3, 10, 3, 45, 54, 758697, tzinfo=<UTC>)},
'e6c7d7a3721ca4b19a5a7f3b34d8387bf': {'id': 'e6c7d7a3721ca4b19a5a7f3b34d8387bf',
'state': 'FINISHED',
'root_id:': 'pc31c89e6b85a4e2c8c5db477978c1a57',
'parent_id': 'pc31c89e6b85a4e2c8c5db477978c1a57',
'version': 'v0c661ee6994d4eb4bdbfe5260f9a9f22',
'loop': 1,
'retry': 0,
'skip': False,
'created_time': datetime.datetime(2021, 3, 10, 3, 45, 54, 767563, tzinfo=<UTC>),
'started_time': datetime.datetime(2021, 3, 10, 3, 45, 54, 767384, tzinfo=<UTC>),
'archived_time': datetime.datetime(2021, 3, 10, 3, 45, 54, 773341, tzinfo=<UTC>)}}}}
恭喜你,你已经成功的创建了一个流程并把它运行起来了!