Code Monkey home page Code Monkey logo

glloq's Introduction

License Apache 2.0 Godoc Actions Status Coverage Status

Glloq

Glloq is a simple command line utility and Go library that lets you take an advisory lock on various backends before running some action. This is especially useful when you want to avoid running database migrations (for example) concurrently.

Officially supported backends currently include:

  • PostgreSQL and derivatives (CockroachDB, …)
  • MySQL and derivatives (MariaDB, …)
  • Local files

but you can very easily implement your own.

Usage

As a CLI

# By default, glloq will use a ".glloq" lock file in the current working directory.
glloq sleep 10 &
glloq echo ok  # This displays "ok" after 10 seconds

# Supported backends include PostgreSQL (CockroachDB, ...), MySQL (Maria, ...) and local files.
export GLLOQ_DSN="postgres://user:password@postgres:5432/mydb?sslmode=disable"

# This wont run concurrently
glloq run_db_migrations.sh

# You can override default timeout of 1 minute to 10 minutes.
export GLLOQ_TIMEOUT=600

# You can specify a lock key (if supported by the backend).
GLLOQ_KEY=concurrent0 glloq run_migrations_0.sh
GLLOQ_KEY=concurrent1 glloq run_migrations_1.sh

As a library

For detailed usage and examples, refer to the godoc page.

import "github.com/gilbsgilbs/glloq"

func lockWithDSN(dsn string) error {
    return glloq.UseLocker(
        &postgreslocker.Locker{}
        &glloq.Options{
            DSN: dsn,
        },
        func() error {
            // Run DB migrations or anything.
        },
    })
}

import "github.com/gilbsgilbs/glloq/postgreslocker"

func lockWithDB(db *sql.DB) error {
    locker := postgreslocker.Locker{}
    locker.DB = db

    return locker.WithLock(
        context.Background(),
        &glloq.Options{},
        func() error {
            // ...
        },
    )
}

glloq's People

Contributors

gilbsgilbs avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

glloq's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

docker-compose
docker-compose.yml
  • postgres 16
  • mysql 8
github-actions
.github/workflows/ci.yml
  • actions/checkout v4
  • golangci/golangci-lint-action v5
  • actions/setup-go v5
  • actions/checkout v4
  • shogo82148/actions-goveralls v1
  • actions/checkout v4
  • actions/setup-go v5
  • goreleaser/goreleaser-action v5
  • postgres 16
  • mysql 8
gomod
go.mod
  • go 1.15
  • github.com/cockroachdb/cockroach-go/v2 v2.3.7
  • github.com/go-sql-driver/mysql v1.7.1
  • github.com/lib/pq v1.10.9
  • github.com/stretchr/testify v1.9.0
  • github.com/theckman/go-flock v0.8.1
  • github.com/xo/dburl v0.23.0

  • Check this box to trigger a request for Renovate to run again on this repository

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.