1. /**
  2. * Teardowns task queues for backward compatibility with rate limiting.
  3. * This function is designed to gracefully shut down task queues, ensuring
  4. * that existing tasks are handled and future tasks are not processed
  5. * after a specified point.
  6. *
  7. * @param {Object} taskQueues - An object containing the task queues to be shut down.
  8. * Expected to have a structure where keys are queue names
  9. * and values are functions that manage the queue.
  10. */
  11. function teardownTaskQueues(taskQueues) {
  12. if (!taskQueues) {
  13. console.warn("teardownTaskQueues: taskQueues is null or undefined. No queues to teardown.");
  14. return;
  15. }
  16. for (const queueName in taskQueues) {
  17. if (taskQueues.hasOwnProperty(queueName)) {
  18. const queue = taskQueues[queueName];
  19. if (typeof queue.stop === 'function') {
  20. queue.stop(); // Stop processing new tasks
  21. console.log(`teardownTaskQueues: Stopped queue ${queueName}`);
  22. } else {
  23. console.warn(`teardownTaskQueues: Queue ${queueName} does not have a 'stop' method. Cannot stop processing.`);
  24. }
  25. if (typeof queue.clear === 'function') {
  26. queue.clear(); // Clear any remaining tasks in the queue
  27. console.log(`teardownTaskQueues: Cleared queue ${queueName}`);
  28. } else {
  29. console.warn(`teardownTaskQueues: Queue ${queueName} does not have a 'clear' method. Cannot clear tasks.`);
  30. }
  31. }
  32. }
  33. }

Add your comment