Skip to content

Instantly share code, notes, and snippets.

@kurtismash
Created February 2, 2023 17:03
Show Gist options
  • Save kurtismash/6b1154377c1d5cc257f985c5106799d1 to your computer and use it in GitHub Desktop.
Save kurtismash/6b1154377c1d5cc257f985c5106799d1 to your computer and use it in GitHub Desktop.
const AWS = require("aws-sdk");
const proxy = require("proxy-agent");
const {
getActivityTask,
sendTaskFailure,
sendTaskHeartbeat,
sendTaskSuccess,
} = require("./awsHelper");
const { worker } = require("./worker");
AWS.config.update({
region: "eu-west-1",
});
const activityRunner = async (heartbeatSecs = 890) => {
const activityArn = process.env.SFN_ACTIVITY_ARN;
let heartbeat;
const task = await getActivityTask(activityArn, "<Activity Worker Name>");
if (!task) return undefined;
const { taskToken, input } = task;
heartbeat = setInterval(() => {
sendTaskHeartbeat(taskToken);
}, heartbeatSecs * 1000);
try {
const result = await worker(input);
await sendTaskSuccess(taskToken, result);
} catch (err) {
await sendTaskFailure(taskToken, err.stack);
} finally {
clearInterval(heartbeat);
}
};
const main = async () => {
while (true) {
await activityRunner();
}
};
main();
module.exports = {
activityRunner,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment