Skip to main content

onestep-cf-queues

Cloudflare Queues connector plugin for onestep. It uses the official cloudflare Python SDK to consume and publish over the HTTP pull-consumer REST API, so it runs from any environment outside Cloudflare Workers.

pip install onestep-cf-queues

The package registers these YAML resource types through the onestep.resources entry point:

  • cf_queues (connector)
  • cf_queue (source + sink)

Python usage:

from onestep import OneStepApp
from onestep_cf_queues import CFQueuesConnector

app = OneStepApp("cf-queues-demo")
cf = CFQueuesConnector(account_id="<account-id>", api_token="<api-token>")
jobs = cf.queue("<queue-id>", batch_size=10, visibility_timeout_ms=30000)


@app.task(source=jobs)
async def consume(ctx, item):
    print("processing", item)

YAML:

resources:
  cf:
    type: cf_queues
    account_id: "${CF_ACCOUNT_ID}"
    api_token: "${CF_QUEUES_TOKEN}"

  jobs:
    type: cf_queue
    connector: cf
    queue_id: "${CF_QUEUE_ID}"
    batch_size: 10
    visibility_timeout_ms: 30000
    on_fail: leave

tasks:
  - name: consume
    source: jobs
    handler:
      ref: your_package.tasks:consume

Prerequisites

  1. Enable HTTP pull on the queue: npx wrangler queues consumer http add <QUEUE-NAME>. A queue cannot have both a Worker (push) consumer and an HTTP (pull) consumer.
  2. Create an API token with the Queues Edit permission (read and write). A pull consumer must be able to write to acknowledge messages.

How it maps to onestep

The connector wraps the official cloudflare SDK's async client (AsyncCloudflare().queues.messages):

onestep cloudflare SDK call
Source.fetch queues.messages.pull(queue_id, account_id=...)
Delivery.ack queues.messages.ack(..., acks=[{lease_id}])
Delivery.retry(delay_s) queues.messages.ack(..., retries=[{lease_id, delay_seconds}])
Sink.send queues.messages.push(...)

Acks and retries are buffered and flushed in batches (ack_batch_size, up to 100 per request) or on a timer (ack_flush_interval_s), then combined into a single /ack call.

Delivery metadata

Fetched messages decode the standard onestep envelope and expose Cloudflare message metadata under delivery.envelope.meta["cf_queues"]:

{
    "id": "1ad27d24c83de78953da635dc2ea208f",
    "timestamp_ms": 1689615013586,
    "attempts": 2,
    "metadata": {"CF-Content-Type": "json"},
}

lease_id is kept internal to ack/retry/release handling and is not exposed on the envelope.

Content types

Attach a pull consumer only to queues whose messages use the text, bytes, or json content type (the default is json). The v8 content type is Workers-only and cannot be decoded. For json and bytes content types the body arrives base64-encoded; the connector decodes base64 automatically before running it through the envelope codec.

Failure handling (on_fail)

  • leave (default): do nothing on failure. The message is re-delivered once its visibility_timeout expires.
  • retry: mark the message for immediate retry (put back in the queue now).
  • ack: acknowledge (drop) the message on failure, e.g. after a dead-letter sink has already handled it.

Short polling and no lease renewal

Unlike SQS long polling, Cloudflare pull uses short polling: fetch returns immediately (empty when there are no messages), so fetch_is_cancel_safe is True. Configure poll_interval_s to control how often the source polls.

Cloudflare Queues has no lease-renewal (heartbeat) endpoint. A message's lease lasts exactly visibility_timeout (default 30s, max 12 hours). For long-running handlers, set visibility_timeout_ms large enough to cover the worst-case processing time, since the lease cannot be extended mid-processing.

Limits

Cloudflare Queues enforces these limits (see the limits docs):

  • Message size: 128 KB.
  • Consumer batch size: up to 100 messages (batch_size, ack_batch_size).
  • visibility_timeout: up to 12 hours.
  • Retry delay_seconds: up to 24 hours.
  • Per-queue throughput: 5,000 messages/second.

Delivery is at-least-once, so make handlers idempotent when duplicates matter.

Metadata

Release files for onestep-cf-queues 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for onestep-cf-queues 0.2.0
File Size Uploaded Provenance
onestep_cf_queues-0.2.0.tar.gz 17.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for onestep-cf-queues 0.2.0
File Interpreter ABI Platform
onestep_cf_queues-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 29.1 kB

Release files / onestep_cf_queues-0.2.0.tar.gz

Download URL onestep_cf_queues-0.2.0.tar.gz
Size 17.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a6eccf7fb4e78dc33f6e6a2c08a27c28b65f42c624368086c79c8ede7cbf5084
BLAKE2b-256 checksum
How to use checksums
9536886c954f7c7283ccfac4fad3affbd664c72726d9e7cd6f223ad7f051b8d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / onestep_cf_queues-0.2.0-py3-none-any.whl

Download URL onestep_cf_queues-0.2.0-py3-none-any.whl
Size 11.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ee463829ab13e690879e0e20500b049793c29a166f511fc3da2ed4b201f69458
BLAKE2b-256 checksum
How to use checksums
8b932ff93296dcbbbc81cf33f32c64d06b97315757a317b254adf39dd2ee86b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for onestep-cf-queues 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page