error-trigger.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * @node error-trigger
  3. * @name Error Trigger
  4. * @category triggers
  5. * @version 1.0.0
  6. * @description Starts a workflow that another workflow nominated to run when it fails, and passes on what failed
  7. * @icon alert-triangle
  8. * @trigger
  9. */
  10. const configSchema = {
  11. type: 'object',
  12. properties: {}
  13. };
  14. const inputSchema = {
  15. type: 'object',
  16. properties: {
  17. data: {
  18. type: 'any',
  19. description: 'Failure details supplied when the workflow was triggered'
  20. }
  21. }
  22. };
  23. const outputSchema = {
  24. type: 'object',
  25. properties: {
  26. failedWorkflowId: { type: 'string', description: 'The workflow that failed' },
  27. failedWorkflowName: { type: 'string', description: 'Its name at the time it failed' },
  28. failedExecutionId: { type: 'string', description: 'The execution that failed' },
  29. error: { type: 'string', description: 'The error it reported' },
  30. failedAt: { type: 'number', description: 'When the failure was recorded, in milliseconds' }
  31. }
  32. };
  33. async function execute(config, input, context) {
  34. // Other triggers report that something happened. This one reports what
  35. // happened, so the details arrive as its input and are passed straight on.
  36. const details = (input && input.data) || input || {};
  37. const failedWorkflowName = details.failedWorkflowName || '';
  38. smartbotic.log.info('Error trigger: handling failure of ' + (failedWorkflowName || 'an unknown workflow'));
  39. return {
  40. failedWorkflowId: details.failedWorkflowId || '',
  41. failedWorkflowName: failedWorkflowName,
  42. failedExecutionId: details.failedExecutionId || '',
  43. error: details.error || '',
  44. failedAt: details.failedAt || Date.now()
  45. };
  46. }
  47. module.exports = { configSchema, inputSchema, outputSchema, execute };