Skip to main content

A simple python CLI application, providing out-of-the-box Redis locking pattern for management of distributed applications in cloud.

Project description

Why LockR?

  • Manage any application in the cloud:
    • It is meant to be a very general purpose CLI tool, to provide applications with distributed locking mechanism, to prevent duplicate instances of the application running at the same time

    • Usable for all sorts of applications (Flask app, Spring boot app, Celery beat/worker etc.) if you want to prevent more than one instance of the app running at the same time.

  • Extremely fault-tolerant:
    • LockR is designed to be resilient to network errors, application problems and so on. So you only need to worry about your own application.

  • Simple to use:
    • LockR is very straightforward to use and maintain

  • No 3rd party dependencies:
    • LockR has been built entirely using in-built python libraries, not relying on any 3rd party libraries.

Setup

  • Redis Server:
    • You need an up and running redis server (or redis cluster), as later you need to specify the hostname and port for the Redis Server

    • Minimum redis version: 2.6.12

Getting started

Install with pip

pip install lockr

You then need a configuration file to tell lockr what to do. Its usually called lockr.ini but can be any name also be anywhere, as long as it is readable and in the right format.

To find usage instructions run:

lockr --help
lockr run --help

A general configuration looks as follows:

# LockR default configuration file
[lockr]
# LockR timeout in milliseconds. Higher values mean it will take longer before a
# downed node is recognized, lower values mean more Redis traffic.
timeout = 1000
# defaults to 1000

# Name of the lock. If empty, generated from the command. Defaults to 'lockr'
lockname = test-lockr

# Command to execute. This is the process you want to start up. MUST BE SPECIFIED
# Examples are: Flask app, celery worker , anything which you don't want to run on more than one node at a time
command = "echo 'test lockr'"


# Whether or not to run command in shell. Defaults to 'no'
use_shell = no

# Specify any custom lock prefix for the lock value stored in key 'lockname'
# Defaults to 'LockR'. Accepts environment variables as well
lock_prefix = test-prefix

[redis]
# defaults to localhost. Specify environment variable or pass directly as well. Conflicts with 'cluster_nodes' (only one can be specified).
host = ${REDIS_HOST}

# Specify all the cluster nodes each in new line. Conflicts with 'host' (only one can be specified).
# Currently only works with environment variables
# The nodes must have cluster mode enabled
cluster_nodes = ${REDIS_HOST}:${REDIS_PORT}

# port is optional and defaults to 6379. Specify environment variable or pass directly as well
port = ${REDIS_PORT}

# In single Redis server mode only, you can SELECT the database. Defaults to 0. Ignored for cluster_nodes
database = 1

All the default parameters are optional, which take the default value if nothing is specified. It is recommended not to update them, unless you want to fine tune your lockr instance.

Then just run:

lockr run --dry-run

If your config file is valid, you should see the output:

Valid configuration found. Dry run verification successful

Once, you’ve confirmed the file is valid, run:

lockr run

Development

LockR is available on GitHub

Once you have the source you can run the tests with the following commands

pip install -r requirements.dev.txt
pytest tests/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lockr-0.1.6.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lockr-0.1.6-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file lockr-0.1.6.tar.gz.

File metadata

  • Download URL: lockr-0.1.6.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for lockr-0.1.6.tar.gz
Algorithm Hash digest
SHA256 74d0cbc8c50e27c4e58ae0e24e3382c9e50f38ed68b456da894703dba7e8cbdc
MD5 497ee12c3eb374c8730ad30b7f85db29
BLAKE2b-256 7cfaa71e730fc8d49970d942784c92b79ba6421f7b877b30cf3b1f0ff911bc3a

See more details on using hashes here.

File details

Details for the file lockr-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: lockr-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for lockr-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 556aa4d595b4e7bb0f3b55963be1c36f5830ae9b88a666907ae33c2572ee393b
MD5 7a2d58341ea8ae1599c6c4ba424988a9
BLAKE2b-256 15d45a361dbddd281d02d9e1be0c23de5f51e30029d2e2b6c6b36ec390773503

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page