Code Monkey home page Code Monkey logo

gcs-mutex-lock's Introduction

gcs-mutex-lock

CircleCI License

A global file-based mutex lock using Google Cloud Storage, inspired by gcslock. Supports retries with exponential backoff via backoff.

The mutex is created with GCS consistency guarantees.

Use Cases

Use this for:

  • If you just want a simple, serverless, global lock
  • High-latency applications (i.e. batch ETL processes)
  • Long-running, distributed compute processes

Don't use this for:

  • Low-latency applications
  • Low-latency locks
  • Client-side applications

Installation

pip install git+https://github.com/thinkingmachines/gcs-mutex-lock.git

Usage

Simple usage:

from gcs_mutex_lock import gcs_lock

# Acquire a lock
acquired = gcs_lock.lock('gs://bucket-name/lock-name')
print(acquired)

# Release the lock
gcs_lock.unlock('gs://bucket-name/lock-name')

Wait for lock to be freed, then acquire it:

# Acquire lock, then retry with (truncated) exponential backoff
acquired = gcs_lock.wait_for_lock_expo('gs://bucket-name/lock-name')
print(acquired)

Backoff

To configure backoff parameters, see the backoff docs.

The backoff parameters can be passed as *args and **kwargs to any of the wait_for_lock* functions.

Exponential Backoff w/Jitter

Use the wait_for_lock_expo for exponential backoff. Full jitter is included by default, so pass jitter=None to see pure exponential behavior.

The default backoff behavior for wait_for_lock_expo is defined in this AWS post.

gcs-mutex-lock's People

Contributors

syvlabs avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.