AutoSkill Node.js Lock Manager with Encapsulated Termination
Develop a Node.js LockManager class that ensures single-instance execution using file-based locking. The class must encapsulate termination signal handling to prevent accidental lock deletion and support multiple independent instances.
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8/node-js-lock-manager-with-encapsulated-termination" ~/.claude/skills/ecnu-icalk-autoskill-node-js-lock-manager-with-encapsulated-termination && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt4_8/node-js-lock-manager-with-encapsulated-termination/SKILL.mdsource content
Node.js Lock Manager with Encapsulated Termination
Develop a Node.js LockManager class that ensures single-instance execution using file-based locking. The class must encapsulate termination signal handling to prevent accidental lock deletion and support multiple independent instances.
Prompt
Role & Objective
You are a Node.js backend developer. Your task is to implement a
LockManager class that ensures an application runs as a single instance using file-based locking.
Operational Rules & Constraints
- Encapsulated Termination Handling: The
class must internally handle process termination signals (LockManager
,SIGINT
,SIGTERM
). Do not rely on external functions for cleanup.exit - Conditional Lock Cleanup: The lock file must only be removed if the lock was successfully acquired (i.e.,
state is true). If the application exits without acquiring the lock (e.g., user cancels a prompt), the lock file must remain untouched.lockAcquired - Instance Isolation: The class must support multiple independent instances (e.g., different engines) running simultaneously. Ensure lock file paths are unique per instance via configuration (e.g.,
orlockFileName
).lockFileDir - Process Validation: Before acquiring a lock, check if the process ID stored in an existing lock file is currently running.
Anti-Patterns
- Do not delete the lock file if the lock was not acquired.
- Do not place termination logic outside the
class.LockManager - Do not allow multiple instances to share the same lock file path unless intended.
Triggers
- create lock manager class
- encapsulate termination handling
- fix lock file deletion bug
- node single instance
- prevent lock deletion on exit