1. /**
  2. * Validates queue data for diagnostics with fixed retry intervals.
  3. * @param {Array<Object>} queues An array of queue objects.
  4. * @param {Object} config Configuration object containing retry interval.
  5. * @returns {Array<Object>} Validated queue objects. Returns an empty array if invalid input.
  6. */
  7. function validateQueues(queues, config) {
  8. if (!Array.isArray(queues)) {
  9. console.error("Invalid input: queues must be an array.");
  10. return [];
  11. }
  12. if (!config || typeof config.retryInterval !== 'number' || config.retryInterval <= 0) {
  13. console.error("Invalid input: config must contain a valid retryInterval (positive number).");
  14. return [];
  15. }
  16. const validatedQueues = [];
  17. for (const queue of queues) {
  18. if (typeof queue !== 'object' || queue === null) {
  19. console.warn("Invalid queue object encountered. Skipping.");
  20. continue;
  21. }
  22. if (typeof queue.name !== 'string' || queue.name.trim() === '') {
  23. console.error("Invalid queue: name must be a non-empty string.");
  24. continue;
  25. }
  26. if (typeof queue.url !== 'string' || queue.url.trim() === '') {
  27. console.error("Invalid queue: url must be a non-empty string.");
  28. continue;
  29. }
  30. if (typeof queue.retryInterval !== 'number' || queue.retryInterval <= 0) {
  31. console.error("Invalid queue: retryInterval must be a positive number.");
  32. continue;
  33. }
  34. validatedQueues.push(queue);
  35. }
  36. return validatedQueues;
  37. }

Add your comment