nocobase-app-plugin-concurrency
Skill này làm gì
Skill này cấu hình dịch vụ khóa cục bộ theo tiến trình trong ứng dụng NocoBase 3. Skill dành cho lập trình viên cần ngăn hai tác vụ cùng thay đổi một thứ tại một thời điểm.
Khi nào nên dùng
- ✓Khi hai yêu cầu có thể cùng thay đổi một bản ghi tại cùng thời điểm.
- ✓Khi bạn cần một khóa đặt tên trong mã phía server của NocoBase.
- ✓Khi bạn muốn cấu hình khóa trong các tệp cấu hình của ứng dụng.
Liên kết skill
https://github.com/nocobase/nocobase/blob/v3-develop/packages/plugins/app-plugin-concurrency/skills/nocobase-app-plugin-concurrency/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Bạn có thể thêm khóa để hai người dùng không thể cùng chạy việc cập nhật tồn kho trong ứng dụng NocoBase của tôi không?”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
AI đăng ký plugin concurrency, thiết lập trình quản lý khóa có tên trong cấu hình, và dùng dịch vụ khóa trong đoạn mã cần nó. Khóa chỉ hoạt động trong một tiến trình đang chạy.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
Concurrency
Install and register
Install @nocobase/app-plugin-concurrency with compatible application-supplied @nocobase/app-server, @nocobase/service-provider and @nocobase/concurrency peers. Register the default /server definition before business plugins and register defineConcurrencyConfig() from /config under concurrency. Installation and both registrations are separate requirements.
The factory supplies default: memory and memory.adapter: mutex, declares CONCURRENCY_DEFAULT and exposes no browser fields. Entry fields are adapter, optional namespace (application name by default), optional ttl, and implementation-owned connection. Mutex forbids connection. TTL is a renewable lease duration, an integer from 1 through 2147483647 milliseconds. Local Mutex accepts and validates TTL but ignores it, with no holding timer, expiration release or local renewal. Resource TTL overrides configuration TTL; undefined retains configuration TTL. Unknown options and invalid selectors fail. Entries do not inherit from one another. Two enabled local entries cannot share a namespace.
Consume the original service
import { concurrencyServiceToken } from '@nocobase/app-plugin-concurrency/server';
const service = app.container.resolve(concurrencyServiceToken);
// Obtain managers in ready or normal running work.
const manager = await service.getManager();
const executor = await manager.createSynchronous('orders:sync');
const result = await executor.tryRun(async () => 'done', 500);
Inject the owner-created Token; never create a second Token or service. The same configuration name shares one manager. Same-name Lock and Executor handles compete in the same domain regardless of TTL. Use bounded, stable resource names: the local native Mutex table remains until instance shutdown. Local locks coordinate only within that instance, never across processes.
lock and run wait without a deadline until success, cancellation or failure. Omitted/zero positional try budgets use native tryAcquire, including its zero-millisecond timer window. Positive try budgets use native withTimeout, not a precise return deadline. Busy results come only from explicit native non-acquisition. Capture each call's signal once; cancellation before delivery must not affect other waiters. Cancellation after delivery does not release a Lease or stop a runner. Late native success after cancellation is released using its own releaser without delivery, runner execution or TTL timer.
Lease release is asynchronous and idempotent; concurrent calls share a result and failures permit explicit retry on the same handle while its instance remains usable. Executors combine Lock acquisition with a no-argument runner, wait for actual runner settlement and diagnose cleanup failure without replacing business values or exceptions. Local Mutex remains held beyond an explicit TTL until manual release, actual runner settlement or instance shutdown. TTL is not a runner timeout or a validity guarantee. Redis implementations use native automatic renewal for both Lock and Executor, not an Executor-owned renewal loop. Use application transactions and idempotency where required.
Lifecycle and extensions
The Provider owns initialization and shutdown. Default startup is eager; named configurations initialize lazily and concurrently share one initialization. Boot freezes the complete snapshot, including unused entries. Reload requires restart to apply changes and never changes active or lazy domains.
Applications stop dependent business work before Concurrency shutdown. Shutdown rejects new acquisitions, interrupts waits, observes issued native requests and actively releases confirmed Leases without draining runners. Release failures are diagnosed while cleanup continues. Concurrent shutdown shares a Promise and successful shutdown is idempotent. Failed owned-resource closure retains its handle for explicit owner service.shutdown() retry. A second app.shutdown() does not repeat cached Provider shutdown. No public operation, cleanup or overall shutdown deadline is configured.
Implementation authors use /server: ManagedLeaseRegistry, startAcquire, createSynchronousExecutor, encodeResourceKey and the original implementation/configuration types. The registry registers confirmed releasers synchronously and owns only Lease release and record disposal, not acquisition, pending work, TTL or renewal. `startAcquire(registry, { si
Câu hỏi thường gặp
Khóa có hoạt động qua nhiều máy chủ không?
Khóa cục bộ chỉ hoạt động trong một tiến trình. Skill mô tả các giới hạn của nó.
Khóa có thể đặt thời gian giới hạn không?
Cài đặt time-to-live được chấp nhận, nhưng khóa cục bộ không sử dụng nó.
Khóa có được lưu trong cơ sở dữ liệu không?
Không. Đó là một dịch vụ khóa nằm trong tiến trình ứng dụng.
Chi tiết
Mô tả gốc của tác giả
Configure and consume NocoBase 3 process-local Mutex locks, strict named managers, original service Token, optional TTL, public implementation extensions and application-owned shutdown.
repo: nocobase/nocobase
Độ phổ biến
- Sao GitHub
- 25k
- Vị trí xếp hạng
- #10094
- Giấy phép
- —
- Cập nhật
- 2/11/2026
Bình luận
- …
Thêm skill từ kho mã này
nocobase-app-development
25kGiúp agent của bạn xây dựng trang, tuyến, dữ liệu, quyền và kiểm thử cho một ứng dụng kinh doanh NocoBase 3 hoàn chỉnh.
shadcn
25kGiúp agent của bạn tìm, thêm, sửa và tạo kiểu cho các thành phần shadcn/ui trong dự án web, dùng tài liệu chính thức và registry của chúng.
nocobase-app-plugin-development
25kGiúp agent của bạn tạo và duy trì plugin NocoBase 3 trong một ứng dụng có sẵn, gồm phần server, client, cơ sở dữ liệu và đăng ký.
nocobase-app-upgrade
25kGiúp agent của bạn nâng cấp ứng dụng NocoBase lên bản mẫu mới hơn, mang các thay đổi của mẫu vào mà vẫn giữ công việc riêng của bạn.
Skill tương tự
api-connector-builder
280kGiúp agent của bạn xây dựng kết nối API mới theo đúng mẫu đã có, dùng khi bạn cần thêm một tích hợp mà không tạo cách làm mới.
api-design
280kGiúp agent của bạn thiết kế REST API theo các thực hành tốt nhất, hữu ích để định nghĩa cách API giao tiếp, hiển thị lỗi và tổ chức dữ liệu.
backend-patterns
280kGiúp agent của bạn với các mẫu kiến trúc phía máy chủ và tối ưu cơ sở dữ liệu, hữu ích khi xây dựng hoặc rà soát code chạy trên máy chủ.