Based on the flow-based programming idea, YAO encapsulates a series of atomic operations into processes; these processes can be called in YAO DSL or JavaScript scripts.
According to business characteristics, YAO defines a set of YAO DSL to describe functional modules such as data structure, data flow, API interface, concurrent tasks, scheduled tasks, and Socket services. These functional modules are defined as Widgets.
When the engine starts, it is parsed into a set of API interfaces and a set of handlers according to the Widget logic. In application development, by writing a Widget DSL to describe the differences, the corresponding functional modules can be implemented, thereby improving coding efficiency.
YAO DSL and YAO Widget support the definition of extensions according to their own business characteristics, which makes it easier to build a low-code platform based on YAO that meets their own business characteristics.
YAO abstracts common function modules into widgets, describes differences through YAO DSL, and quickly replicates various functions.
During development, if you develop a similar function module, you need to copy and paste the existing functions and replace the differences in batches.
YAO provides a new way to use DSL to describe the difference content and quickly "copy and paste" a function module to improve development efficiency.
models/ccategory.mod.json
file and write the following:Use yao migrate -n category
to migrate data table files
Create a new category table tables/category.tab.json
code:
New flows/category.flow.json
{"label": "Category Tree","version": "1.0.0","description": "Category Tree","nodes": [{"name": "Category","engine": "xiang","query": {"select": ["id", "name", "name as label", "id as value", "parent_id"],"wheres": [{ ":deleted_at": "deleted", "=": null }],"from": "category","limit": 1000}},{"name": "Category Tree","process": "xiang.helper.ArrayTree","args": ["{{$res.category}}", { "parent": "parent_id" }]}],"output": "{{$res.category tree}}"}
##Widget API
New apis/select.http.json
{"name": "Drop down search","version": "1.0.0","description": "Drop down search","guard": "bearer-jwt","group": "select","paths": [{"path": "/category","method": "GET","process": "flows.category","in": [],"out": {"status": 200,"type": "application/json"}}]}
Run yao start
, visit 127.0.0.1:5099/api/select/category
/tasks/task.js
:{"name": "Test task","worker_nums": 10,"attempts": 3,"attempt_after": 200,"timeout": 2,"size": 1000,"process": "scripts.task.Send","event": {"next": "scripts.task.NextID","add": "scripts.task.OnAdd","success": "scripts.task.OnSuccess","error": "scripts.task.OnError","progress": "scripts.task.OnProgress"}}
Parameters | Meaning | Description |
---|---|---|
name | Task name | |
worker_nums | Specifies the number of processes | |
attempts | Number of failed retries | |
attempt_after | retry interval | |
timeout | timeout period | |
process | The process bound to this task | |
next | Generate task unique id | |
add | Method triggered when a task is added | |
success | Trigger method after successful task processing | |
error | Trigger method after task failure | |
progress | Called during task processing |
New scripts/task.js
New route apis/task.http.json
{"name": "Task","version": "1.0.0","description": "Task","guard": "","group": "task","paths": [{"path": "/task","method": "GET","process": "scripts.test.task","in": [],"out": {"status": 200,"type": "application/json"}}]}
New test function scripts/test.js
function task() {for (i = 1; i < 100; i++) {Process("tasks.test.Add", "Enter task" + i);}}
Run the project yao start
and visit the url 127.0.0.1:5099/api/task/task
to see the print information
/schedules/test.sch.json
, the writing method of the scheduled task is the same as the Linux crontab, the code:{"name": "Called every minute","schedule": "*/1 * * * *","process": "scripts.schedules.Send","args": []}
scripts/schedules.js
code:function Send() {console.log("Enter the scheduled task!");}
Execute yao start
and wait for 1 minute to see the print information
Based on the flow-based programming idea, YAO encapsulates a series of atomic operations into processes; these processes can be called in YAO DSL or JavaScript scripts.
According to business characteristics, YAO defines a set of YAO DSL to describe functional modules such as data structure, data flow, API interface, concurrent tasks, scheduled tasks, and Socket services. These functional modules are defined as Widgets.
When the engine starts, it is parsed into a set of API interfaces and a set of handlers according to the Widget logic. In application development, by writing a Widget DSL to describe the differences, the corresponding functional modules can be implemented, thereby improving coding efficiency.
YAO DSL and YAO Widget support the definition of extensions according to their own business characteristics, which makes it easier to build a low-code platform based on YAO that meets their own business characteristics.
YAO abstracts common function modules into widgets, describes differences through YAO DSL, and quickly replicates various functions.
During development, if you develop a similar function module, you need to copy and paste the existing functions and replace the differences in batches.
YAO provides a new way to use DSL to describe the difference content and quickly "copy and paste" a function module to improve development efficiency.
models/ccategory.mod.json
file and write the following:Use yao migrate -n category
to migrate data table files
Create a new category table tables/category.tab.json
code:
New flows/category.flow.json
{"label": "Category Tree","version": "1.0.0","description": "Category Tree","nodes": [{"name": "Category","engine": "xiang","query": {"select": ["id", "name", "name as label", "id as value", "parent_id"],"wheres": [{ ":deleted_at": "deleted", "=": null }],"from": "category","limit": 1000}},{"name": "Category Tree","process": "xiang.helper.ArrayTree","args": ["{{$res.category}}", { "parent": "parent_id" }]}],"output": "{{$res.category tree}}"}
##Widget API
New apis/select.http.json
{"name": "Drop down search","version": "1.0.0","description": "Drop down search","guard": "bearer-jwt","group": "select","paths": [{"path": "/category","method": "GET","process": "flows.category","in": [],"out": {"status": 200,"type": "application/json"}}]}
Run yao start
, visit 127.0.0.1:5099/api/select/category
/tasks/task.js
:{"name": "Test task","worker_nums": 10,"attempts": 3,"attempt_after": 200,"timeout": 2,"size": 1000,"process": "scripts.task.Send","event": {"next": "scripts.task.NextID","add": "scripts.task.OnAdd","success": "scripts.task.OnSuccess","error": "scripts.task.OnError","progress": "scripts.task.OnProgress"}}
Parameters | Meaning | Description |
---|---|---|
name | Task name | |
worker_nums | Specifies the number of processes | |
attempts | Number of failed retries | |
attempt_after | retry interval | |
timeout | timeout period | |
process | The process bound to this task | |
next | Generate task unique id | |
add | Method triggered when a task is added | |
success | Trigger method after successful task processing | |
error | Trigger method after task failure | |
progress | Called during task processing |
New scripts/task.js
New route apis/task.http.json
{"name": "Task","version": "1.0.0","description": "Task","guard": "","group": "task","paths": [{"path": "/task","method": "GET","process": "scripts.test.task","in": [],"out": {"status": 200,"type": "application/json"}}]}
New test function scripts/test.js
function task() {for (i = 1; i < 100; i++) {Process("tasks.test.Add", "Enter task" + i);}}
Run the project yao start
and visit the url 127.0.0.1:5099/api/task/task
to see the print information
/schedules/test.sch.json
, the writing method of the scheduled task is the same as the Linux crontab, the code:{"name": "Called every minute","schedule": "*/1 * * * *","process": "scripts.schedules.Send","args": []}
scripts/schedules.js
code:function Send() {console.log("Enter the scheduled task!");}
Execute yao start
and wait for 1 minute to see the print information