Skip to content

Commit

Permalink
use a lock file in cwd
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbsgilbs committed Oct 8, 2020
1 parent f25bc2f commit abe4f66
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/dist/
/glloq
*.lock
*.glloq

# Created by https://www.toptal.com/developers/gitignore/api/go
# Edit at https://www.toptal.com/developers/gitignore?templates=go
Expand Down
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@ but you can very easily implement your own.
### As a CLI

```bash
# Supported DSNs include PostgreSQL (CockroachDB, ...), MySQL (Maria, ...), Files.
export GLLOQ_DSN=postgres://user:password@postgres:5432/mydb?sslmode=disable
# By default, glloq will use a ".glloq" lock file in the current working directory.
glloq sleep 10 &
glloq echo ok # This displays "ok" in 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_migrations.sh
glloq run_db_migrations.sh

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

# You can specify a lock ID (if the back-end supports it)
# 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
```
Expand Down
5 changes: 1 addition & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"os"
"os/exec"
"path"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -39,9 +38,7 @@ func RunGlloq(env []string, args []string) (int, error) {

dsn := opts["dsn"]
if dsn == "" {
// No DSN set, just use a static file.
tmpdir := os.TempDir()
dsn = "file://" + path.Join(tmpdir, "glloq-edw3KBE")
dsn = "file://.glloq"
}
timeoutSeconds, _ := strconv.Atoi(opts["timeout"])
lockerOptions := glloq.Options{
Expand Down

0 comments on commit abe4f66

Please sign in to comment.