Giter Site home page Giter Site logo

keyway's Introduction

dP
88
88  .dP  .d8888b. dP    dP dP  dP  dP .d8888b. dP    dP
88888"   88ooood8 88    88 88  88  88 88'  `88 88    88
88  `8b. 88.  ... 88.  .88 88.88b.88' 88.  .88 88.  .88
dP   `YP `88888P' `8888P88 8888P Y8P  `88888P8 `8888P88
                       .88                          .88
                   d8888P                       d8888P

Keyway

A simple lock file library.

Features
  • Provides mutual exclusion for scripts that require the same resource.
  • Requires three additional lines of code in your script, including sourcing the library.
  • Scripts using Keyway can be configured to either terminate or busy-wait if a resource is blocked.
  • Keyway will report when an external error was caught and there are lock files in the lock directory.
Usage:
  • acquire_lock_for "your_task_name"
    • If the resource is not locked, your task will execute, otherwise it will terminate.
  • acquire_spinlock_for "your_task_name"
    • If the resource is locked, your task will wait until the lock has been released before acquiring its own lock and executing.
Return Code Explanations:
  1. Your application was not able to acquire lock.
  2. There was some other problem:
    • Keyway could not create the lock directory.
    • Keyway could not create or remove a lock.
  3. An error was caught and there are lock files in the lock directory.
An example:
#!/bin/bash
source keyway_lib.sh

# optionally override the lock file directory
LOCK_DIR="alt-lock-dir"

# attempt to lock the shared resource
acquire_lock_for "your_task_name"

# if the lock was successful, execute the task
echo "executing critical section"

# release the lock when the task is done
release_lock_for "your_task_name"

keyway's People

Contributors

mattantonelli avatar maurotdo avatar trevors avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.