Class: TaskExecutor
executor/executor.TaskExecutor
A high-level module for defining and executing tasks in the golem network
Table of contents
Methods
High-level
create
▸ Static
create(options
): Promise
<TaskExecutor
>
Create a new Task Executor
Description
Factory Method that create and initialize an instance of the TaskExecutor
Example
Simple usage of Task Executor
The executor can be created by passing appropriate initial parameters such as package, budget, subnet tag, payment driver, payment network etc. One required parameter is a package. This can be done in two ways. First by passing only package image hash, e.g.
const executor = await TaskExecutor.create("9a3b5d67b0b27746283cb5f287c13eab1beaa12d92a9f536b747c7ae");
Example
Usage of Task Executor with custom parameters
Or by passing some optional parameters, e.g.
const executor = await TaskExecutor.create({
subnetTag: "public",
payment: { driver: "erc-20", network: "rinkeby" },
package: "9a3b5d67b0b27746283cb5f287c13eab1beaa12d92a9f536b747c7ae",
});
Parameters
Name | Type | Description |
---|---|---|
options |
ExecutorOptionsMixin |
Task executor options |
Returns
Promise
<TaskExecutor
>
TaskExecutor
Defined in
yajsapi/executor/executor.ts:108
Other
init
▸ init(): Promise
<void
>
Initialize executor
Description
Method responsible initialize all executor services.
Returns
Promise
<void
>
Defined in
yajsapi/executor/executor.ts:147
end
▸ end(): Promise
<void
>
Stop all executor services and shut down executor instance
Returns
Promise
<void
>
Defined in
yajsapi/executor/executor.ts:170
getStats
▸ getStats(): Object
Statistics of execution process
Returns
Object
array
Defined in
yajsapi/executor/executor.ts:190
beforeEach
▸ beforeEach(worker
): void
Define worker function that will be runs before every each computation Task, within the same activity.
Example
executor.beforeEach(async (ctx) => {
await ctx.uploadFile("./params.txt", "/params.txt");
});
await executor.forEach([1, 2, 3, 4, 5], async (ctx, item) => {
await ctx
.beginBatch()
.run(`/run_some_command.sh --input ${item} --params /input_params.txt --output /output.txt`)
.downloadFile("/output.txt", "./output.txt")
.end();
});
Parameters
Name | Type | Description |
---|---|---|
worker |
Worker <unknown , unknown > |
worker function - task |
Returns
void
Defined in
yajsapi/executor/executor.ts:213
run
▸ run<OutputType
>(worker
): Promise
<undefined
| OutputType
>
Run task - allows to execute a single worker function on the Golem network with a single provider.
Example
Type parameters
Name | Type |
---|---|
OutputType |
Result |
Parameters
Name | Type | Description |
---|---|---|
worker |
Worker <undefined , OutputType > |
function that run task |
Returns
Promise
<undefined
| OutputType
>
result of task computation
Defined in
yajsapi/executor/executor.ts:227
map
▸ map<InputType
, OutputType
>(data
, worker
): AsyncIterable
<undefined
| OutputType
>
Map iterable data to worker function and return computed Task result as AsyncIterable
Example
const data = [1, 2, 3, 4, 5];
const results = executor.map(data, (ctx, item) => providerCtx.ctx(`echo "${item}"`));
for await (const result of results) console.log(result.stdout);
Type parameters
Name |
---|
InputType |
OutputType |
Parameters
Name | Type | Description |
---|---|---|
data |
Iterable <InputType > |
Iterable data |
worker |
Worker <InputType , OutputType > |
worker function |
Returns
AsyncIterable
<undefined
| OutputType
>
AsyncIterable with results of computed tasks
Defined in
yajsapi/executor/executor.ts:244
forEach
▸ forEach<InputType
, OutputType
>(data
, worker
): Promise
<void
>
Iterates over given data and execute task using worker function
Example
const data = [1, 2, 3, 4, 5];
await executor.forEach(data, async (ctx, item) => {
console.log((await ctx.run(`echo "${item}"`).stdout));
});
Type parameters
Name |
---|
InputType |
OutputType |
Parameters
Name | Type | Description |
---|---|---|
data |
Iterable <InputType > |
Iterable data |
worker |
Worker <InputType , OutputType > |
Worker function |
Returns
Promise
<void
>