Skip to main content

Clear Queue

Removes all elements from an in-memory queue without deleting the queue itself. The queue remains available for new elements to be enqueued.

Common Properties

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing the node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.
info

If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.

Inputs

  • Queue ID - The unique queue identifier returned from the Create Queue node.

How It Works

The Clear Queue node removes all elements from the specified queue while keeping the queue structure intact. When executed, the node:

  1. Validates the Queue ID exists
  2. Retrieves the queue from memory
  3. Removes all elements from the queue
  4. Resets the queue to empty state
  5. Queue ID remains valid and can be used for new operations

This is useful when you want to reuse a queue without creating a new one.

Examples

Example 1: Clear After Processing

Queue before:

["item1", "item2", "item3", "item4", "item5"]

Operation:

Clear Queue (Queue ID: queueId)

Queue after:

[]

Result: Queue is now empty but still exists and can accept new items.

Example 2: Reset Between Batches

Process items in batches, clearing between each batch:

1. Create Queue → queueId
2. Loop for each batch:
- Read batch data
- For each item in batch:
- Enqueue item to queueId
- Process all queued items
- Clear Queue (queueId)
3. Delete Queue when all batches done

Example 3: Error Recovery

Clear queue after handling errors:

1. Create Queue → taskQueueId
2. Enqueue all tasks
3. Try:
- Process tasks
4. Catch:
- Log error
- Clear Queue (taskQueueId)
- Re-enqueue only valid tasks
- Retry processing

Example 4: Conditional Reset

Clear queue based on certain conditions:

1. Process queue items
2. If error_count > threshold:
- Log "Too many errors, clearing queue"
- Clear Queue
- Reset error counter
3. Otherwise:
- Continue processing

Example 5: Reuse Queue for Different Data

Use the same queue for different purposes:

1. Create Queue → workQueueId

Phase 1:
2. Enqueue URLs
3. Process URLs
4. Clear Queue

Phase 2:
5. Enqueue email addresses
6. Send emails
7. Clear Queue

Phase 3:
8. Enqueue file paths
9. Process files
10. Delete Queue

Use Cases

  • Batch processing - Clear queue between different batches of data
  • Error recovery - Remove invalid items and restart with clean slate
  • Queue reuse - Use same queue for different purposes without recreating
  • Workflow reset - Reset queue state during long-running automations
  • Memory management - Free memory from processed items while keeping queue
  • Testing - Reset queue to known state during debugging

Error Handling

The node will return errors in the following cases:

  • ErrInvalidArg - Queue ID is invalid or empty
  • ErrNotFound - Queue with the specified ID does not exist

Common Errors and Solutions

Error: "queue with id ... does not exist"

Cause: The Queue ID is invalid or queue was already deleted.

Solution:

  • Verify Queue ID is correct
  • Ensure queue wasn't deleted before Clear operation
  • Check that Queue ID variable is properly set
  • Create queue if it doesn't exist

Tips and Best Practices

  • Clear vs Delete - Use Clear to keep the queue, Delete to remove it completely
  • Clear before reuse - Clear existing queue instead of creating multiple queues
  • Memory efficiency - Clear processed items to free memory in long-running automations
  • State reset - Use Clear to reset queue to known empty state
  • Batch boundaries - Clear between batches to prevent mixing data
  • Error handling - Clear queue when recovering from errors
  • Testing - Clear queue between test runs for consistent state

Performance Considerations

  • Fast operation - Clear is an immediate, in-memory operation
  • Memory release - All elements are removed and memory is freed
  • Thread-safe - Safe to use with concurrent access
  • No data loss risk - Only clears if you explicitly call it
  • Queue ID preserved - Same Queue ID continues to work after clear

Clear vs Delete vs Dequeue All

OperationQueue Exists AfterElementsQueue IDUse Case
ClearYesRemovedSameReuse queue
DeleteNoRemovedInvalidFinished with queue
Dequeue AllYesRemovedSameProcess each item

Choose Clear when:

  • You want to reuse the queue
  • Processing in batches
  • Recovering from errors
  • Resetting state

Choose Delete when:

  • Completely done with queue
  • Want to free all resources
  • Queue no longer needed

Choose Dequeue All when:

  • Need to process each element
  • Want to act on each item
  • Order of processing matters

Processing Patterns

Pattern 1: Batch Processing with Clear

1. Create Queue → queueId
2. For each batch in dataset:
- Enqueue all batch items
- Process all items
- Clear Queue
3. Delete Queue

Pattern 2: Error Recovery

1. Try:
- Process queue items
2. Catch:
- Clear Queue
- Enqueue only valid items
- Retry

Pattern 3: Workflow Phases

Phase 1:
- Enqueue phase1 data
- Process
- Clear

Phase 2:
- Enqueue phase2 data
- Process
- Clear

Phase 3:
- Enqueue phase3 data
- Process
- Delete Queue

Pattern 4: Conditional Clear

1. Process items
2. If condition met:
- Clear remaining items
- Move to next step
3. Else:
- Continue processing

Integration Examples

Example: Multi-Stage Processing

1. Create Queue → queueId

Stage 1 - Collect URLs:
2. Enqueue all product URLs
3. Process and extract product IDs
4. Clear Queue

Stage 2 - Collect Details:
5. Enqueue all product IDs
6. Fetch product details
7. Clear Queue

Stage 3 - Process Orders:
8. Enqueue all orders
9. Process orders
10. Delete Queue

Example: Error-Tolerant Processing

1. Create Queue → queueId
2. Enqueue all tasks
3. error_count = 0
4. While queue not empty:
- Try:
- Dequeue → task
- Process task
- Catch:
- error_count += 1
- If error_count > 10:
- Log errors
- Clear Queue
- Break

When to Use Clear

Good use cases:

  • Processing data in phases or batches
  • Recovering from errors by resetting queue
  • Reusing queue for different types of data
  • Implementing circuit breaker patterns
  • Cleaning up partially processed data

Not recommended:

  • If you need to process items individually (use Dequeue instead)
  • When completely done with queue (use Delete instead)
  • Just to check if queue is empty (check element count instead)

Memory Management

Clearing a queue:

  • Frees memory used by elements
  • Keeps queue structure in memory
  • Resets internal counters
  • Maintains thread-safety guarantees
  • Preserves Queue ID

For complete memory cleanup, use Delete Queue instead.