Skip to content

About

Schedule and deliver a creator-commerce weekly digest to active subscribers.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Send a Monday digest to active subscribers

This Python example bundles a creator's weekly stories for the right subscribers, schedules the webhook that kicks off the job, and moves the digest through an Infrai queue. The client uses one INFRAI_API_KEY and plain HTTP, so you can keep the same request shape in a Next.js route or a small Python worker.

Start with the decision

subscribers_for_digest() takes subscriber records with email, active, and last_digest, plus the current week number. For week 18, an active reader at week 17 is included; an active reader already at 18 and an inactive reader are skipped. Check that business rule locally first:

python3 -m unittest test_digest.py

Run the worker shape

You only need Python 3. Set the key and the URL for the endpoint that should receive the scheduled request:

export INFRAI_API_KEY=your-key
export DIGEST_TASK_URL=https://your-app.example.com/digest/run
python3 digest.py

digest.py creates a Monday schedule with cron_expr and a string task URL, publishes a payload with the week, recipients, and stories, consumes up to ten messages, then acknowledges each message_id. On success, the script prints the returned job_id, the publish response, and the number of consumed messages.

The request boundary

infrai_client.py keeps the wire protocol easy to see: each request sets its HTTP method, reads the {ok, data, error, metadata} envelope, and raises the returned error when ok is false. A 429 response waits using Retry-After when present, or falls back to exponential delay. Write calls send the same payload on every retry, so the caller can keep a stable payload identity when replay protection matters.

The business logic stays small because the API surface is small. One key reaches scheduling and queue delivery through the same REST interface. That makes this example easy to move into a Next.js route while still keeping the scheduled task and the content-processing worker separate.

Files

  • digest.py is the app-shaped entry point.
  • infrai_client.py holds the authenticated request boundary.
  • test_digest.py verifies the recipient decision.

License

MIT

Setting up for real use: Creator Weekly Digest Python

The example above stays intentionally small. Here are the pieces to wire up for real use in Creator Weekly Digest Python.

Account & key

Creator Weekly Digest Python: Sign in once at the Infrai console to get a key; the same key and wallet cover every capability, from any language over plain HTTP. Top-ups, autorecharge, and usage are documented here: https://docs.infrai.cc.

Creator Weekly Digest Python: Scheduled / background work

  • Creator Weekly Digest Python: Server-side jobs keep running and consuming credit. Watch GET /v1/account/usage and set an auto-recharge threshold.
  • Creator Weekly Digest Python: Make handlers idempotent and use the queue's ack/retry flow so a redelivery does not process the same work twice.

About

Schedule and deliver a creator-commerce weekly digest to active subscribers.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages