JS Task API Reference

Class: TaskExecutor

executor.TaskExecutor

A high-level module for defining and executing tasks in the golem network

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new TaskExecutor(options)

Create a new TaskExecutor object.

Parameters

NameTypeDescription
optionsTaskExecutorOptionsTaskExecutorOptions

Defined in

executor.ts:221

Properties

events

Readonly events: EventEmitter<ExecutorEvents, any>

Defined in

executor.ts:143


glm

Readonly glm: GolemNetwork

This object is the main entry-point to the basic golem-js api. Allows you to listen to events from core golem-js modules such as market, payment, etc. Provides full access to the low-level api intended for more advanced users

Defined in

executor.ts:149

Methods

create

Static create(options): Promise<TaskExecutor>

Create a new Task Executor

Parameters

NameTypeDescription
optionsTaskExecutorOptionsTask executor options

Returns

Promise<TaskExecutor>

TaskExecutor

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 market, payment, payment etc.

Example

Usage of Task Executor with custom parameters

const executor = await TaskExecutor.create({
  logger: pinoPrettyLogger({ level: "info" }),
  demand: {
    workload: {
      imageTag: "golem/alpine:latest",
    },
  },
  market: {
    rentHours: 0.5,
    pricing: {
      model: "linear",
      maxStartPrice: 0.5,
      maxCpuPerHourPrice: 1.0,
      maxEnvPerHourPrice: 0.5,
    },
  },
});

Defined in

executor.ts:210


init

init(): Promise<void>

Initialize executor Method responsible for connecting to the golem network and initiating all required services.

Returns

Promise<void>

Defined in

executor.ts:238


shutdown

shutdown(): Promise<void>

Stop all executor services and shut down executor instance.

You can call this method multiple times, it will resolve only once the executor is shutdown.

When shutdown() is initially called, a beforeEnd event is emitted.

Once the executor is fully stopped, an end event is emitted.

Returns

Promise<void>

Defined in

executor.ts:286


getStats

getStats(): Object

Returns

Object

NameType
retriesundefined | number
providersnumber
agreementsnumber
invoicesReceivednumber
invoicesPaidnumber
invoicesUnpaidnumber
invoicesMissingnumber
invoicePaymentRatenumber

Defined in

executor.ts:315


run

run<OutputType>(taskFunction, options?): Promise<OutputType>

Run task - allows to execute a single taskFunction function on the Golem network with a single provider.

Type parameters

Name
OutputType

Parameters

NameTypeDescription
taskFunctionTaskFunction<OutputType>function that run task
options?TaskOptionstask options

Returns

Promise<OutputType>

result of task computation

Example

await executor.run(async (exe) => console.log((await exe.run("echo 'Hello World'")).stdout));

Defined in

executor.ts:333


cancel

cancel(reason): Promise<void>

Parameters

NameType
reasonstring

Returns

Promise<void>

Defined in

executor.ts:374

Was this helpful?