在对象上执行复杂操作的框架
dj-actions的Python项目详细描述
DJ操作
比crud稍微复杂一点的工作框架。
- []使用数据结构定义复杂的工作流
- []自我记录
- []复合动作的高级模块化结构
- []监控行动和进度
- []重播
- []反向
- []时间旅行
开始
安装:
pip install dj-actions
将应用程序添加到“已安装的应用程序”:
INSTALLED_APPS = [
..
'actions',
]
你的第一个动作
dj-actions
使用ACTION_MAP
设置来定义任务如何映射到代码。
有一些策略可以生成你的动作图,但是yaml并不是一个坏的选择。在settings.py
importyamlaction_yml="""hello_world: name: "HelloWorld" example_payload: msg: "hello!", tasks: sync: - name: say_hi execute: actions.tasks.debug.hello"""ACTIONS_MAP=yaml.load(action_yml)
。或者使用get_action_map
帮助程序:
from actions.helpers import get_action_map
ACTION_MAP = get_action_map([
'example_project/actions.yml',
'path/to/some/other/actions.yml'
])
现在您可以使用以下命令执行此操作:
fromaction.modelsimportActionInstanceactor=get_user_model().objects.first()payload={"msg":"hi!"}action=ActionInstance.from_config(actor,'hello_world',payload=payload)action.run()
api
您可以添加一个api:
urls.py
fromactions.apiimportrouterasactions_routerurlpatterns=[...path('actions/',include(actions_router.urls)),]
文件
您的ACTION_MAP
可以为您生成文档:
依赖项:
我们以更聪明的人的工作为基础。
- Django
- django rest框架
附加组件/插件:
- 哨兵
- DJ NoSQL->;推入Firestore等
- streamio->;推入流
- 。
概念
触发器
。
动作
。
动作实例
。
创建操作
POST /actions/:resourceName/:verb/:id/
{
payload: { .. }
}
例如:/actions/invoice/send/123/
型号:
classAction:''' Stores an incoming request so that it can be tracked and replayed if necessary '''slug# used to look up action in Catalogpayload(json)filesactor(user)# models are stored as: `myapp.models.MyModel:id`# tasks can add models as they gomodelscontext(json)# tasks can add to context as they gostatusclassTaskExecutionStatus:''' Tasks must record their execution status for the action '''incomingaction(fk)taskstatusinputouputnotesclassRegisteredAction:""" A calalog of available actions and their definitions """titledescriptiondocumentation# markdown docs for this actionslugpayload_map# optional, map a payload to arguments for the taskpermission_tasks:[],validation_tasks:[],sync_tasks:[],async_tasks:[],scheduled_tasks:[]classRegisteredTask:""" Library of available tasks """titledescriptiondocumentationinvokation# e.g.: path.to.my_taskclassActionEvent:actor(user)contexttemplateparsedobject_ids# object ids which control who can see this event
库提供的任务:
add_to_feed
->;在发生操作时添加ActionEvents
trigger_action
->;创建一个新的Action
添加自定义任务包:
- 提供一个python应用程序
- 应用程序应该有一个名为
register_tasks
的管理脚本。你可以猜出那是什么