Skip to content

Instantly share code, notes, and snippets.

@herecydev
Last active December 27, 2018 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save herecydev/6f053cdb4319d2be76a4b46ef49d609f to your computer and use it in GitHub Desktop.
Save herecydev/6f053cdb4319d2be76a4b46ef49d609f to your computer and use it in GitHub Desktop.
timehandler.js
const taskHandler = async (task) => {
try {
const start = Date.now();
log.info("Executing {taskId}", { taskId: task.taskId });
const handler = await import(`handlers/${task.taskId}`);
const result = await handler.execute(task);
const end = Date.now();
log.info("Task Handler {taskId} succeeded in {time}ms", { taskId: task.taskId, time: end - start });
return result;
}
catch (error) {
log.error(error, "Task Handler {taskId} failed", { taskId: task.taskId });
return -1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment