Skip to content

Commit

Permalink
Merge pull request #7 from coligo-tech/dev
Browse files Browse the repository at this point in the history
Release version 1.0.3
  • Loading branch information
AmrSaber committed May 1, 2021
2 parents 9a93455 + 96575fb commit c28ceb5
Show file tree
Hide file tree
Showing 11 changed files with 1,286 additions and 1,370 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: CI

on:
pull_request:
branches:
- master
- dev

jobs:
run-linter:
name: Run linter
runs-on: ubuntu-latest
container: node:14.16-slim

steps:
- uses: actions/checkout@v2

- name: Install Dependencies
run: npm ci

- name: Lint
run: npm run lint

run-tests:
name: Run tests
runs-on: ubuntu-latest
container: node:14.16-slim

services:
redis:
image: redis:6.2-alpine

steps:
- uses: actions/checkout@v2

- name: Install Dependencies
run: npm ci

- name: Test
env:
REDIS_URI: redis://redis:6379
run: npm run test
33 changes: 0 additions & 33 deletions .github/workflows/lint.yml

This file was deleted.

15 changes: 15 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
on:
push:
branches:
- master

jobs:
publish:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1

- uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.NPM_TOKEN }}
33 changes: 9 additions & 24 deletions .github/workflows/test-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,19 @@ jobs:
run-tests:
name: Run tests
runs-on: ubuntu-latest
container: node:14.16-slim

services:
redis:
image: redis:6.2-alpine

steps:
- uses: actions/checkout@v2

- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: 12.x

- name: Start Redis
uses: supercharge/redis-github-action@1.1.0
with:
redis-version: 6

- name: Cache node modules
uses: actions/cache@v1
env:
cache-name: cache-node-modules
with:
path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install Dependencies
run: npm ci

- name: Run Tests
run: npm test
- name: Test
env:
REDIS_URI: redis://redis:6379
run: npm run test
33 changes: 9 additions & 24 deletions .github/workflows/test-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,19 @@ jobs:
run-tests:
name: Run tests
runs-on: ubuntu-latest
container: node:14.16-slim

services:
redis:
image: redis:6.2-alpine

steps:
- uses: actions/checkout@v2

- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: 12.x

- name: Start Redis
uses: supercharge/redis-github-action@1.1.0
with:
redis-version: 6

- name: Cache node modules
uses: actions/cache@v1
env:
cache-name: cache-node-modules
with:
path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install Dependencies
run: npm ci

- name: Run Tests
run: npm test
- name: Test
env:
REDIS_URI: redis://redis:6379
run: npm run test
43 changes: 0 additions & 43 deletions .github/workflows/test.yml

This file was deleted.

8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ async function lock(client, lockName, { retryTimeMillis = 100, timeoutMillis, fa

const acquireLock = new Promise((resolve, reject) => {
let failTimeoutId = null;
let attemptTimeoutId = null;

// Try to acquire the lock, and try again after a while on failure
function attempt() {
Expand All @@ -36,15 +37,18 @@ async function lock(client, lockName, { retryTimeMillis = 100, timeoutMillis, fa
if (failTimeoutId != null) { clearTimeout(failTimeoutId); }
resolve();
} else {
setTimeout(attempt, retryTimeMillis);
attemptTimeoutId = setTimeout(attempt, retryTimeMillis);
}
});
}

// Set time out to fail acquiring the lock if it's sent
if (failAfterMillis != null) {
failTimeoutId = setTimeout(
() => { reject(new Error(`Lock could not be acquire for ${failAfterMillis} millis`)); },
() => {
if (attemptTimeoutId != null) { clearTimeout(attemptTimeoutId); }
reject(new Error(`Lock could not be acquire for ${failAfterMillis} millis`));
},
failAfterMillis,
);
}
Expand Down

0 comments on commit c28ceb5

Please sign in to comment.