You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This example demonstrates how HyperFlow can communicate with remote job executors using Redis.
1
+
## Distributed execution of workflow Jobs using Redis
2
+
This example explains the distributed execution model of Hyperflow. It demonstrates how HyperFlow can communicate with remote job executors using Redis. It is also useful for testing the implementation of the [Hyperflow job executor](https://github.com/hyperflow-wms/hyperflow-job-executor).
3
3
4
-
- The workflow invokes function `submitRemoteJob` from `functions.js` 100 times. This function simulates submission of jobs by starting 100 parallel processes of `node handler.js <taskId> <redis_url>`.
5
-
-`handler.js` represents a remote job executor which is passed two parameters: `taskId` and `redis_url`.
6
-
-`handler.js` gets a `jobMessage` from HyperFlow, and then sends back a notification that the job has completed; `taskId` is used to construct appropriate Redis keys for this communication.
7
-
- On the HyperFlow engine side, the Process Function can use two functions: `context.sendMsgToJob` to send a message to the job, and `context.jobResult` to wait for the notification. These functions return a [`Promise`](https://javascript.info/promise-basics), so the async/await syntax can be used as shown in the example.
4
+
The distributed execution architecture consists of:
5
+
1. Master components:
6
+
-**The Hyperflow engine** - executes the workflow graph; for each workflow task it invokes the **Job invoker** function
7
+
-**Job invoker** - Javascript function which creates jobs on a (remote) infrastructure to execute workflow tasks
8
+
-**Redis server** - used for communication between the Hyperflow engine and Job executors on remote workers
9
+
1. Worker components:
10
+
-**Hyperflow job executor** - receives the job command from the Hyperflow engine and spawns application software
11
+
-**Application software** - software that actually performs workflow tasks
12
+
13
+
In this example:
14
+
- The workflow has two tasks (see `workflow.json`): one that executes `job.js`, the other which simply runs `ls -l`. Note that the commands to be executed are specified in `workflow.json`.
15
+
- The engine invokes the function `submitRemoteJob` (Job invoker) from `functions.js`. This function simulates submission of jobs by starting the Hyperflow job executor and communicating with it via Redis to run jobs.
16
+
-`../../../hyperflow-job-executor/handler.js` represents a remote job executor which is passed two parameters: `taskId` and `redis_url`. The executor gets a `jobMessage` from HyperFlow, executes the command in a separate process, and then sends back a notification that the job has completed; `taskId` is used to construct appropriate Redis keys for this communication.
17
+
- On the HyperFlow engine side, the Job invoker can use two functions (provided by Hyperflow): `context.sendMsgToJob` to send a message to the job executor, and `context.jobResult` to wait for the notification from the executor. These functions return a [`Promise`](https://javascript.info/promise-basics), so the async/await syntax can be used as shown in the example.
8
18
- The parameter to the `context.jobResult` function is a timeout in seconds (0 denotes infinity). One can use a retry library, such as [promise-retry](https://www.npmjs.com/package/promise-retry), to implement an exponential retry strategy.
9
-
- The Process Function also gets the Redis URL in `context.redis_url` which can be passed to the remote job executors.
19
+
- The Job invoker also gets the Redis URL in `context.redis_url` which can be passed to the remote job executors.
10
20
11
-
To run the workflow, simply do `hflow run .` in this directory. You might need to run once `npm install` to install dependencies.
21
+
To run the workflow, execute the following commands:
22
+
1. First, clone the Hyperflow engine and the Hyperflow job executor:
0 commit comments