Skip to content

Latest commit

 

History

History
267 lines (161 loc) · 5.12 KB

File metadata and controls

267 lines (161 loc) · 5.12 KB

iexec


iexec / IExecTaskModule

Class: IExecTaskModule

module exposing task methods

Extends

Constructors

Constructor

new IExecTaskModule(configOrArgs, options?): IExecTaskModule

Create an IExecModule instance

Parameters

configOrArgs

IExecConfigArgs | IExecConfig

options?

IExecConfigOptions

Returns

IExecTaskModule

Inherited from

IExecModule.constructor

Properties

config

config: IExecConfig

current IExecConfig

Inherited from

IExecModule.config

Methods

claim()

claim(taskid): Promise<string>

SIGNER REQUIRED

claim a task not completed after the final deadline (proceed to refunds).

example:

const claimTxHash = await claim(taskid);
console.log('task claimed:', claimTxHash);

Parameters

taskid

string

Returns

Promise<string>


fetchLogs()

fetchLogs(taskid): Promise<object[]>

SIGNER REQUIRED, ONLY REQUESTER

get the workers logs for specified task.

NB: the workerpool must declare it's API url to enable this feature, check declared API url with IExecWorkerpoolModule.getWorkerpoolApiUrl(workerpool)

example:

const logArray = await fetchLogs('0x668cb3e53ebbcc9999997709586c5af07f502f6120906fa3506ce1f531cedc81');
logsArray.forEach(({ worker, stdout, stderr }) => {
  console.log(`----- worker ${worker} -----`);
  console.log(`stdout:\n${stdout}`);
  console.log(`stderr:\n${stderr}`);
});

Parameters

taskid

string

Returns

Promise<object[]>


fetchOffchainInfo()

fetchOffchainInfo(taskid): Promise<{ replicates: object[]; task: { status: string; statusHistory: object[]; }; }>

get off-chain status information for specified task.

NB: the workerpool must declare it's API url to enable this feature, check declared API url with IExecWorkerpoolModule.getWorkerpoolApiUrl(workerpool)

example:

const { task, replicates } = await fetchOffchainInfo('0x668cb3e53ebbcc9999997709586c5af07f502f6120906fa3506ce1f531cedc81');

console.log(`task status: ${task.status}`);
replicates.forEach(({ worker, status }) =>
  console.log(`worker ${worker} replicate status: ${status}`)
);

Parameters

taskid

string

Returns

Promise<{ replicates: object[]; task: { status: string; statusHistory: object[]; }; }>


fetchResults()

fetchResults(taskid): Promise<Response>

IPFS stored results only

download the specified task result.

example:

const response = await fetchResults('0x668cb3e53ebbcc9999997709586c5af07f502f6120906fa3506ce1f531cedc81');
const binary = await response.blob();

Parameters

taskid

string

Returns

Promise<Response>


obsTask()

obsTask(taskid, optional?): Promise<TaskObservable>

return an Observable with a subscribe method to monitor the task status changes.

NB: specify the dealid of the task to allow task monitoring when the task is not yet initialized (ACTIVE)

example:

  • monitor task updates
const taskObservable = await obsTask('0xec8045dfb0235d46c2d7ece1eadfe7741728754aed8b7efb716e9890cf3e9a8d');
const unsubscribe = taskObservable.subscribe({
 next: ({ message, task }) => console.log(message, task.statusName),
 error: (e) => console.error(e),
 complete: () => console.log('final state reached'),
});
// call unsubscribe() to unsubscribe from taskObservable
  • wait for task completion
const waitFinalState = (taskid, dealid) =>
  new Promise((resolve, reject) => {
    let taskState;
    iexec.task.obsTask(taskid, { dealid }).subscribe({
      next ({task}) => taskState = task,
      error: e => reject(e),
      complete: () => resolve(taskState),
    });
  });
const task = await waitFinalState(
  '0xec8045dfb0235d46c2d7ece1eadfe7741728754aed8b7efb716e9890cf3e9a8d',
  '0x4246d0ddf4c4c728cedd850890ee9a6781a88e5d3c46098c0774af3b7963879b',
);

Parameters

taskid

string

optional?
dealid?

string

Returns

Promise<TaskObservable>


show()

show(taskid): Promise<Task>

show the details of a task.

example:

const task = await show(
 '0xec8045dfb0235d46c2d7ece1eadfe7741728754aed8b7efb716e9890cf3e9a8d',
);
console.log('task:', task);

Parameters

taskid

string

Returns

Promise<Task>


fromConfig()

static fromConfig(config): IExecTaskModule

Create an IExecTaskModule instance using an IExecConfig instance

Parameters

config

IExecConfig

Returns

IExecTaskModule

Overrides

IExecModule.fromConfig