CLI

Use LockDB in any OS with the CLI.

Install

You can find the binary for your system in the latest release.

Here's an example for Linux intel (x86_64), on downloading it with curl and moving it to /usr/local/bin/ so it's available globally as lockdb:

# Download the binary from the latest release for your system and move it to `/usr/local/bin/`. Here's an example for most Linux OSes:
curl -L https://github.com/BrunoBernardino/lockdb/releases/latest/download/lockdb-linux-intel --output lockdb && \
chmod +x lockdb && \
sudo mv lockdb /usr/local/bin/

Usage

# Set ENV variables
export LOCKDB_SERVICE_ID="reports"
export LOCKDB_API_KEY="api-key"

# Check on a lock
lockdb check sales
# Outputs `false`

# Obtain a lock, waiting up to 30 seconds for it
lockdb lock sales
# Outputs `true` or a TimeoutError

# Unlock a lock, returning if it was locked before
lockdb unlock sales
# Outputs `true`

# Check on multiple locks
lockdb check sales,report,cleanup
# Outputs `false`

Options

Here are all the optional arguments in all commands.

# Locking
lockdb lock sales --service-id="reports" --api-key="api-key" --server-url="https://api.lockdb.com" --wait-timeout-in-ms=30000 --unlock-webhook-url="https://example.com" --lock-expiration-in-s=300

# Locking, short arguments version
lockdb lock sales -i "reports" -a "api-key" -s "https://api.lockdb.com" -w 30000 -u "https://example.com" -l 300

# Unlocking
lockdb unlock sales --service-id="reports" --api-key="api-key" --server-url="https://api.lockdb.com" --wait-timeout-in-ms=5000

# Checking
lockdb check sales --service-id="reports" --api-key="api-key" --server-url="https://api.lockdb.com" --wait-timeout-in-ms=5000

# Alternatively, you can set environment variables for `--service-id`, `--api-key`, and `--server-url`, and omit those arguments:
export LOCKDB_SERVICE_ID="reports"
export LOCKDB_API_KEY="api-key"
export LOCKDB_SERVER_URL="https://api.lockdb.com"