Public API to send ready-made messages in a batch and to flush open batches

Open
#165 0 comments 0 reactions 1 assignee View on GitHub

@fbidu is already working on this.

Since Nov 10, 2026.

Assessment

This issue has not been assessed yet.

Description

Callers that batch sends with add_batch() sometimes need to do more than the public API allows, and today the only way is to reach into JobQueue._batch_level, JobQueue._batched_messages and JobQueue._flush_batch_if_needed(). This issue tracks adding public methods for those cases so callers can stop depending on private state.

What's missing

  1. Sending a ready-made message that respects an open batch. add_raw_job() always takes a job name and adds the ContentType, JobContext and JobName message attributes, so a caller that publishes messages in another envelope format (for a consumer that isn't sqs-workers) can't use it. There's no public way to hand over plain send_message kwargs and have them join the current batch, or go out right away when no batch is open.
  2. Flushing every open batch now. close_add_batch() closes one nesting level. A process that is about to exit without unwinding its add_batch() blocks (for example, a web request killed on its timeout) needs to close all levels and send what's pending immediately.
  3. Knowing how many messages are pending. The same caller reports how much work was waiting in the batch, and needs that number even if the flush fails.

Proposal

  • JobQueue.add_raw_message(**kwargs): appends the kwargs to the batch when one is open, otherwise calls send_message(**kwargs) on the queue.
  • JobQueue.flush_add_batch(): closes every open level and sends everything pending.
  • JobQueue.pending_messages: read-only property with the number of messages waiting in the batch.

Names are a first proposal, happy to change them.

Done when

  • The three are public, documented in the changelog and covered by tests (no batch, open batch, nested batches, and an empty flush that doesn't look up the queue).
  • A release ships them.
Dominant language
Python
Stars
37
Forks
8
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Doist/sqs-workers

All issues in Doist/sqs-workers

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.