Package Exports
- step-function-worker
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (step-function-worker) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
step-function-worker
Create a nodejs aws step-function worker/pooler easily :-)
install
npm install step-function-worker
Example usage
Basic example
var fn = function(input, cb, heartbeat){
// do something
doSomething(input)
// call heartbeat sometime to avoid timeout
heartbeat()
// call callback in the end
cb(null, {"foo" : "bar"}); // output must be compatible with JSON.stringify
};
var worker = new StepFunctionWorker({
activityArn : '<activity-ARN>',
workerName : 'workerName',
fn : fn,
concurrency : 2 // default is 1
});
Set the Region
By default, this package is built on top of aws-sdk
so you should set your AWS Region by changing AWS_REGION
environment variable.
If you want to set it in JS code directly you can do it using awsConfig
(see https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Config.html to see all available options) like
var worker = new StepFunctionWorker({
activityArn : '<activity-ARN>',
workerName : 'workerName',
fn : fn,
awsConfig: {
region: '<your-region>'
}
});
Close the worker
// when finish close the worker with a callback
// this closing process may take up to 60 seconds per concurent worker, to close all connections smoothly without loosing any task
worker.close(function(){
process.exit();
})
Events
worker.on('task', function(task){
// task.taskToken
// task.input
console.log("task ", task.input)
});
worker.on('failure', function(failure){
// out.error
// out.taskToken
console.log("Failure :",failure.error)
});
worker.on('heartbeat', function(beat){
// out.taskToken
console.log("Heartbeat");
});
worker.on('success', function(out){
// out.output
// out.taskToken
console.log("Success :",out.output)
});
worker.on('error', function(err){
console.log("error ", err)
});
Documentation
See JSDoc in the code.