UNPKG

2.91 kBMarkdownView Raw
1dataflo.ws task is a flow building block.
2
3Tasks are described using configuration, which includes code reference to run,
4input parameters, output parameter and meta.
5
6### Example
7
8```json
9"tasks": [{
10 "$promise": "fetchDBRecordById",
11 "$args": {
12 "id": "123"
13 },
14 "$set": "record",
15 "$setOnEmpty": "noRecord"
16}, {
17 "task": "urlData",
18 "if": "{$noRecord}",
19 "url": "http://apiserver/db-records/123",
20 "$set": "recordDataResponse"
21}, {
22 "$function": "JSON.parse",
23 "$args": "{$recordDataResponse.data}",
24 "$set": "recordData"
25}, {
26 "$promise": "insertDBRecord",
27 "$args": {
28 "id": "{$recordData.id}",
29 "name": "{$recordData.name}"
30 },
31 "$set": "record"
32}, {
33 "$function": "console.log",
34 "$args": "{$record}"
35}]
36```
37
38### Variables
39
40As you may noticed, there is some magic values within strings.
41Main purpose of those magic values is task requirements declaration
42and dataflow description. You can read it like:
43
44```
45recordDataResponse.data is a parameter of JSON.parse
46urlData provides recordDataResponse
47we need to launch JSON.parse after urlData is completed and recordDataResponse.data is true value
48```
49
50In the current stage we have only two expansions: true value (`{$key}`) and any value (`{*key}`);
51
52### Task code
53
54Task code reference can be:
55
561. function with immediate return value — synchronous, keys: `fn`, `$function`;
572. function with node-styled callback (errback) — asynchronous, keys: `errback`, `$errback`;
583. promise — asynchronous, keys: `promise`, `$promise`;
594. task class — asynchronous, `task`, `$class`, TODO: take a look into [TASKCLASS](TASKCLASS.md).
605. TODO: special case — every task;
615. TODO: special case — flow task;
62
63Functions and promises is looked up in `require.main.exports`, tasks is a regular node modules
64and usually lies within `node_modules/task` directory.
65
66### Task requirements
67
68Task requirements need to be fulfilled before task launch. Those requirements can be
69input task parameters or just values in task configuration. Task will not receive second ones,
70they're only evaluated at task launch stage. `urlData` task won't launch unless
71key `{$noRecord}` is not set.
72
73### Input parameters
74
75Input parameters for tasks is defined by $args key. If value for that key
76is object, string, boolean or number then object will be the first parameter of function arguments.
77If $args is array, array items became function arguments
78
79### Output parameters
80
81When task return value, this value can be omited or used in flow data. You can:
82
831. Write value to the key in flow data when task succeeds with `$set`;
841. Merge returned object with key in flow data when task succeeds with `$mergeWith`;
851. Write value to the key in flow data when task succeeds, but don't provided a true value with `$setOnEmpty` (bad key name, I know);
861. Write value to the key in flow data when task fails, with `$setOnFail`;
87
88Key name must be a plain string, not the expansion.
89