reliability-concurrency
仓库创建 2024年12月9日最近提交 6 小时前SkillHot 收录 5 小时前
▸ 精选理由
针对生产并发场景的实战指南,能显著降低数据损坏风险。
这个 Skill 做什么
提供并发、重试与幂等模式,防止多 worker 竞态与数据损坏。
给写并发/重试代码的人一套实战模式,防止多 worker 竞态、重复执行或数据损坏,适用于 BullMQ worker、分片迁移、替换式写入或任何可能被重试的多步骤操作。上线 worker 任务、迁移 runner 或替换写入前要先看这些模式。亮点是提供 advisory lock、幂等(idempotency)、事务和安全重试的具体做法,把竞态变成可控流程。
▸ 展开 SKILL.md 英文原文
Use when writing code that runs concurrently in ChatbotX — BullMQ worker consumers, sharded DB migrations, embedding replace-writes, or any multi-step operation that could be retried or run by two workers at once. Covers advisory locks, idempotency, transactions, and safe-retry patterns. Read before adding a worker job, migration runner, or replace-style write.
524
Stars
116
Forks
21
仓库内 Skill
积累中
7 日增星
安装 / 使用
给你的 Agent 一句话(通用)
帮我安装这个 skill:https://raw.githubusercontent.com/ChatbotXIO/ChatbotX/main/.agents/skills/reliability-concurrency/SKILL.md或 curl 直取 SKILL.md
curl -fsSL "https://raw.githubusercontent.com/ChatbotXIO/ChatbotX/main/.agents/skills/reliability-concurrency/SKILL.md"SKILL.MD 节选查看完整文件 ↗
# Reliability & Concurrency (ChatbotX) Production runs multiple worker instances and re-tries failed jobs. Code that is correct single-threaded can corrupt data when two workers race or a job re-runs. Apply these patterns. ## 1. Guard schema/DDL changes with an advisory lock Migration runners (e.g. `packages/database/src/sharding/message/shard-migration-runner.ts`) must not let two workers apply the same DDL concurrently. Wrap the apply loop: - Take a `pg_advisory_lock` (or `pg_try_advisory_lock`) keyed on the shard before reading the current version. - Do the version check and each migration apply inside a transaction so a crash mid-step rolls back. - Make "read version → apply → write
via SKILL·HOT · 数据来自 GitHub 公开信息 · 原文版权归作者所有