Cursor rule
.cursor/rules/background-tasks.mdcBackground task lifecycle, shutdown ordering, and loop invariants
Cursor rules
Quality
58/100
Scores the file, not the repository.Length
210 words
6 headings · 1 code blocksRepository
0
— · pushed 54 days agoLast changed
3 days ago
First indexed 3 days ago.1234567# Background Task Lifecycle89Background tasks (`WorkerPool`, `EsIndexer`, `RollupScheduler`) follow a10`start()` / `stop()` shape with an `asyncio.Event` stop signal and a single11`asyncio.create_task(..., name=...)`. The skeleton matters less than the12decisions below — get these wrong and you lose data or hang a deploy.1314## Drain vs. cancel on `stop()` (a correctness decision)1516- If the task holds **un-acked, un-persisted work**, drain it before cancelling.17 `WorkerPool.stop()` does `await queue.join()` with a timeout, *then* cancels.18- If the task's work is **idempotent / replayable** (the outbox re-indexes, the19 next tick re-aggregates), set the stop event and cancel directly —20 `EsIndexer` / `RollupScheduler`.2122When adding a task, ask: would cancelling mid-flight lose anything? That answer23picks the variant.2425## Loop invariants2627- Idle interruptibly — never block shutdown for a full interval:2829```python30# ✅ wakes immediately on stop31try:32 await asyncio.wait_for(self._stop_event.wait(), timeout=self._interval)33except asyncio.TimeoutError:34 pass # interval elapsed35# ❌ asyncio.sleep(self._interval) # ignores the stop signal36```3738- The loop body **catches and logs**, never lets an exception kill the task.39- Consumers must call `task_done()` for every `get()`, even on error.4041## Shutdown ordering in `app/main.py` lifespan4243`ingestion.stop_accepting()` → `worker.stop()` (drain) → `es_indexer.stop()` →44`rollup.stop()` → **then** close Mongo/ES/Redis clients. Never close a client a45running task still uses.46
Also in jleist-clemson/acheron
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| jleist-clemson/acheron.cursor/rules/api-routes.mdc · 0 | Cursor rules | styleapi | 57/100 | 3 days ago | |
| jleist-clemson/acheron.cursor/rules/elasticsearch-mapping.mdc · 0 | Cursor rules | styletypesdo-not | 58/100 | 3 days ago | |
| jleist-clemson/acheron.cursor/rules/python-standards.mdc · 0 | Cursor rules | lint-formatapido-notdocs | 72/100 | 3 days ago | |
| jleist-clemson/acheron.cursor/rules/testing.mdc · 0 | Cursor rules | testlint-formatstyletesting-strategy | 67/100 | 3 days ago | |
| jleist-clemson/acheronAGENTS.md · 0 | AGENTS.md | testlint-formatstyledo-not+2 | 63/100 | 3 days ago | |
| jleist-clemson/acheronCLAUDE.md · 0 | CLAUDE.md | agent-behaviour | 16/100 | 3 days ago |
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| TechSquidTV/Hermes.cursor/rules/10-hermes-api.mdc · 45 | Cursor rules | testlint-formatstylearch+5 | 100/100 | 3 days ago | |
| TechSquidTV/Hermes.cursor/rules/20-hermes-api-tests.mdc · 45 | Cursor rules | teststyletesting-strategysecurity+3 | 97/100 | 3 days ago | |
| langflow-ai/langflow.cursor/rules/docs_development.mdc · 153k | Cursor rules | setupbuildtestlint-format+7 | 97/100 | 3 days ago | |
| nerds-odd-e/doughnut.cursor/rules/cli.mdc · 49 | Cursor rules | setupbuildteststyle+4 | 96/100 | 3 days ago | |
| pr-pm/prpm.cursor/rules/github-actions-testing.mdc · 121 | Cursor rules | setupbuildstylearch+4 | 93/100 | 3 days ago | |
| pr-pm/prpm.cursor/rules/creating-agents-md.mdc · 121 | Cursor rules | testlint-formatstylearch+7 | 92/100 | 3 days ago | |
| coollabsio/coolify.cursor/rules/coolify-ai-docs.mdc · 60k | Cursor rules | buildteststylearch+5 | 92/100 | 3 days ago | |
| iloveitaly/llm-ide-rules.cursor/rules/general.mdc · 13 | Cursor rules | teststyledo-notagent-behaviour+1 | 92/100 | 3 days ago |
