Class: Job<Output>
job/job.Job
This API is experimental and subject to change. Use at your own risk.
The Job class represents a single self-contained unit of work that can be run on the Golem Network. It is responsible for managing the lifecycle of the work and providing information about its state. It also provides an event emitter that can be used to listen for state changes.
Type parameters
Name | Type |
---|---|
Output | unknown |
Table of contents
Constructors
Properties
Methods
Constructors
constructor
• new Job<Output
>(id
, yagnaApi
, defaultOptions?
): Job
<Output
>
Create a new Job instance. It is recommended to use GolemNetwork to create jobs instead of using this constructor directly.
Type parameters
Name | Type |
---|---|
Output | unknown |
Parameters
Name | Type |
---|---|
id | string |
yagnaApi | YagnaApi |
defaultOptions | Partial <RunJobOptions > |
Returns
Job
<Output
>
Defined in
Properties
events
• Readonly
events: EventEmitter
<JobEventsDict
, any
>
Defined in
results
• results: undefined
| Output
Defined in
error
• error: undefined
| Error
Defined in
state
• state: TaskState
= JobState.New
Defined in
id
• Readonly
id: string
Defined in
Methods
isRunning
▸ isRunning(): boolean
Returns
boolean
Defined in
startWork
▸ startWork(workOnGolem
, options?
): void
Run your worker function on the Golem Network. This method will synchronously initialize all internal services and validate the job options. The work itself will be run asynchronously in the background. You can use the Job.events event emitter to listen for state changes. You can also use Job.waitForResult to wait for the job to finish and get the results. If you want to cancel the job, use Job.cancel. If you want to run multiple jobs in parallel, you can use GolemNetwork.createJob to create multiple jobs and run them in parallel.
Parameters
Name | Type | Description |
---|---|---|
workOnGolem | Worker <Output > | Your worker function that will be run on the Golem Network. |
options | RunJobOptions | Configuration options for the job. These options will be merged with the options passed to the constructor. |
Returns
void
Defined in
cancel
▸ cancel(): Promise
<void
>
Cancel the job. This method will stop the activity and wait for it to finish. Throws an error if the job is not running.
Returns
Promise
<void
>
Defined in
waitForResult
▸ waitForResult(): Promise
<unknown
>
Wait for the job to finish and return the results. Throws an error if the job was not started.
Returns
Promise
<unknown
>