iexec / IExecTaskModule
module exposing task methods
new IExecTaskModule(
configOrArgs,options?):IExecTaskModule
Create an IExecModule instance
IExecTaskModule
config:
IExecConfig
current IExecConfig
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);string
Promise<string>
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}`);
});string
Promise<object[]>
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}`)
);string
Promise<{ replicates: object[]; task: { status: string; statusHistory: object[]; }; }>
fetchResults(
taskid):Promise<Response>
IPFS stored results only
download the specified task result.
example:
const response = await fetchResults('0x668cb3e53ebbcc9999997709586c5af07f502f6120906fa3506ce1f531cedc81');
const binary = await response.blob();string
Promise<Response>
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',
);string
string
Promise<TaskObservable>
show(
taskid):Promise<Task>
show the details of a task.
example:
const task = await show(
'0xec8045dfb0235d46c2d7ece1eadfe7741728754aed8b7efb716e9890cf3e9a8d',
);
console.log('task:', task);string
Promise<Task>
staticfromConfig(config):IExecTaskModule
Create an IExecTaskModule instance using an IExecConfig instance
IExecTaskModule