Search…
Executable Structure
For local testing, the file must have the same name as filecoin CID or task name entered in the task creation
An executable is structured as follows, the setup and execute function will be called and the API endpoints defined will be established.
Example executable file:
const cron = require('node-cron');
const NODE_MODE_SERVICE = 'service';
​
/**
* @description Setup function is the first function that is called in executable to setup the node
*/
async function setup() {
console.log('Running setup function');
// Run default setup
await namespace.defaultTaskSetup();
// Run any extra setup here
}
​
/**
* @description Using to validate an individual node. Returns true if node is valid
*
* The value passed to this function contains the value submitted to chain
* and optionally the url for the node
*/
async function validateNode(node) {
console.log("Validating Node", node);
// Return true if node is valid
return true;
}
​
/**
* @description Execute function is called just after the setup function to run Submit, Vote API in cron job
* @returns return all cron schedule from execute function for graceful termination
*/
async function execute() {
console.log('Running execute function');
console.log('NODE MODE', process.env.NODE_MODE);
let cronArray = [];
if (process.env.NODE_MODE == NODE_MODE_SERVICE) {
cronArray.push(
cron.schedule('*/1 * * * *', namespace.checkSubmissionAndUpdateRound),
);
}
cronArray.push(cron.schedule('*/1 * * * *', () => { namespace.validateAndVoteOnNodes(validateNode) }));
​
return cronArray;
}
​
​
if (namespace.app) {
// Write your Express Endpoints here.
// For Example
//namespace.express('post', '/accept-cid', async (req, res) => {})
}
Copy link