# Schedule posts

Schedule Bluesky posts with a persistent Python queue: preview safely, handle late runs, cancel work and review uncertain delivery before retrying.

[HTML version](https://bluesky.bot/docs/schedule-posts)

A timed bot needs a worker that knows **what remains due**, and a scheduler that starts it. This tutorial uses a persistent local SQLite queue. You run it on a machine you control; Bluesky.bot does not host or execute the bot.

The kit requires Python 3.11+. It previews by default and keeps stable job identities. A rolling 15-minute window can duplicate overlapping runs and miss delayed work, so it is not the delivery mechanism used here.

## Why a future timestamp is not enough

A post's `createdAt` is a declared timestamp, not a publish-later instruction. Keep the due date in a queue and wait until the worker reaches it. The kit supports plain text and an optional article link, not threads or media. For a first SDK post, use the [Python](https://bluesky.bot/docs/python-bot) or [TypeScript](https://bluesky.bot/docs/typescript-bot) tutorial.

## Install and preview

[Download the queue and RSS fixtures](https://bluesky.bot/api/tutorials/bot-recipes), extract the package and run its offline tests. No account is needed for these tests.

```bash
tar -xzf bluesky-bot-recipes.tar.gz
cd bluesky-bot-recipes
python3 -m unittest -v test_recipes.py
python3 -m venv .venv
. .venv/bin/activate
python -m pip install -r requirements.txt
```

The tests simulate publication, competing workers and lost responses. They do not prove an authenticated post succeeded. The SDK is needed only when you enable publication.

## Queue timezone-aware jobs

Edit `schedule.json` with your text, a stable `id` and a due date containing `Z` or a numeric UTC offset. Replace the committed 20 November 2026 example before publishing. A bare `08:00` has no date or timezone and is refused.

```bash
python3 posting_queue.py --db .state/queue.sqlite3 load schedule.json
python3 posting_queue.py --db .state/queue.sqlite3 run
python3 posting_queue.py --db .state/queue.sqlite3 status
```

Default `run` prints due text without logging in, claiming a job or marking it sent. Re-loading an unchanged ID preserves state and its reserved record key. Changed content under the same ID is refused: cancel a pending job and use a new ID for a genuinely new post.

08:00 with `+01:00` is 07:00 UTC. A fixed offset is not a recurring Europe/Paris timezone rule; daylight-saving transitions can change it. Convert each intended date deliberately. Check text with the [character counter](https://bluesky.bot/tools/character-counter); this teaching kit conservatively accepts at most 300 Unicode code points.

## Publish one checked job

Follow the [app-password guide](https://bluesky.bot/guides/bluesky-app-passwords). Keep `BLUESKY_HANDLE` and `BLUESKY_APP_PASSWORD` in protected local configuration. Set `BLUESKY_SERVICE` to the account's actual HTTPS PDS if hosted elsewhere.

```bash
python3 posting_queue.py --db .state/queue.sqlite3 run --publish
python3 posting_queue.py --db .state/queue.sqlite3 status
```

One due job is attempted by default; `--limit 5` is a ceiling, not a recommended publishing frequency. No due work means no login. The database binds to the bot's DID on its first publishing run; use a separate database per bot.

Check the real post and URI in Bluesky before unattended use. The worker stores its first claim time as `createdAt`, separately from the due date.

## Run with cron and persistent state

Keep the database on a persistent writable local disk, outside temporary deployment/CI workspaces, with the same path on every run. Back it up. SQLite locking prevents competing workers claiming the same job; a lost database or unreliable network filesystem is outside this kit's recovery guarantee.

Put credentials in an owner-readable environment file, not directly in crontab. This Unix example requires replacing all paths, creating state/log directories and protecting the environment file before use:

```bash
*/15 * * * * cd /home/bot/recipes && set -a && . /home/bot/.config/bluesky-bot.env && set +a && /home/bot/recipes/.venv/bin/python posting_queue.py --db /home/bot/.local/state/bluesky-bot/queue.sqlite3 run --publish >> /home/bot/.local/state/bluesky-bot/worker.log 2>&1
```

This checks every 15 minutes; it does not promise an exact publication minute. A late pending job remains due. A confirmed job remains sent. Start with small batches and inspect the backlog after an outage.

For feed input, use the [RSS-to-Bluesky tutorial](https://bluesky.bot/guides/rss-to-bluesky): the importer enqueues articles, and the worker publishes them. An article removed from a short feed before polling cannot be recovered by this queue.

## Handle cancellations and uncertain delivery

Only pending jobs can be cancelled. A local status change does not delete an already published remote post.

```bash
python3 posting_queue.py --db .state/queue.sqlite3 cancel JOB_ID
python3 posting_queue.py --db .state/queue.sqlite3 status
python3 posting_queue.py --db .state/queue.sqlite3 resolve JOB_ID --as sent --reviewed
```

The worker commits `publishing` before the external call. An exception becomes `review`; a crash may leave `publishing`. Neither state is automatically replayed: a timeout may occur after the PDS accepted the post.

Stop all workers, then inspect the public record at the `rkey` shown by `status` with the [repository explorer](https://bluesky.bot/tools/repo-explorer). Verify its content. Mark an existing confirmed record `sent`. Only after establishing that no record exists should you consider `--as pending --reviewed`, which retains its key. If uncertain, leave it for review. This requires human reconciliation; it is not an exactly-once guarantee across two systems.

## Avoid fragile scheduled workflows

GitHub documents scheduled runs as best effort: they may be delayed or dropped, and schedules use the default branch. A fresh hosted runner does not automatically retain an SQLite file from its previous job.

Use this local-disk recipe with cron, or design persistent external storage, serialization and reconciliation before adapting it to ephemeral CI. Uploading state only after publication leaves a crash window. Neither this page nor the download enables a workflow or scheduled job.

## Troubleshoot and verify the bot

- **Nothing due:** inspect the UTC date, pending state and database path. Sent, cancelled and uncertain jobs are intentionally not pending.
- **Late work:** verify the scheduler started and the persistent disk survived. Inspect batch size before clearing a backlog.
- **Login refused:** check the bot account, dedicated credential and current PDS. Do not loop over sign-in.
- **Rate limit:** stop, honor the server's retry guidance and review outstanding writes. Read the [official limits](https://bsky.network/docs/rate-limits/).
- **Lost state:** stop automation and reconstruct outcomes from public records before rebuilding the queue. A new database or new job ID is not a safe retry.

Follow the [automation best practices](https://bluesky.bot/docs/best-practices). The MIT kit can be reused without a required backlink. Its offline tests are reproducible; authenticated acceptance and hosting remain your own deliberate steps.

Sources reviewed on 19 November 2026: [post schema](https://github.com/bluesky-social/atproto/blob/b9b1ca7f176b93d12e39685799c5f2e1f9a63be7/packages/api/lexicons/app/bsky/feed/post.json), [GitHub schedule behavior](https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#schedule), [SQLite transactions](https://www.sqlite.org/lang_transaction.html), and [timezone-aware datetimes](https://docs.python.org/3/library/datetime.html).
