schedule-parser.js 997 B

1234567891011121314151617181920212223242526272829
  1. /** 语句:schedule 定时执行(解析在此,执行在 sequence-runner) */
  2. const { assertStrictKeys } = require('../action-schema.js')
  3. const types = ['schedule']
  4. function parse (action, parseContext) {
  5. const path = parseContext.actionPath || 'schedule'
  6. assertStrictKeys(action, ['type', 'condition', 'interval'], path)
  7. if (action.condition == null || typeof action.condition !== 'object' || Array.isArray(action.condition)) {
  8. throw new Error(`${path}: schedule 须包含对象 condition`)
  9. }
  10. if (!Array.isArray(action.interval)) {
  11. throw new Error(`${path}: schedule 须包含数组 interval`)
  12. }
  13. const condition = { ...action.condition }
  14. if (condition.repeat === 'forever' || condition.repeat === 'Forever') {
  15. condition.repeat = -1
  16. }
  17. return {
  18. type: 'schedule',
  19. condition,
  20. interval: parseContext.parseActions(action.interval, 'interval'),
  21. }
  22. }
  23. async function execute() {
  24. return { success: true }
  25. }
  26. module.exports = { types, parse, execute }