Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/npm_and_yarn/mongodb-5.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewmolyuk committed Apr 2, 2024
2 parents 7ea26e2 + 826a4bb commit 0f90b1f
Show file tree
Hide file tree
Showing 9 changed files with 3,507 additions and 1,695 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/lint-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Lint & Test

# Trigger the workflow on push or pull request commits only
on:
push:
branches:
- master
tags-ignore:
- '**'
pull_request:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: make lint
18 changes: 0 additions & 18 deletions .github/workflows/pull_request.yml

This file was deleted.

12 changes: 7 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
name: Release version
name: Release

# Trigger the build on release tag push only
on:
push:
branches:
- master
tags:
- '**'

jobs:
build:
Expand All @@ -11,11 +13,11 @@ jobs:
- uses: actions/checkout@master
- uses: actions/cache@master
with:
path: "**/node_modules"
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
- uses: actions/setup-node@master
with:
node-version: "12.x"
node-version: '12.x'
- run: npm install
- run: npm run eslint
- name: Bump version and push tag
Expand Down
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SHELL := /bin/bash

lint:
npx eslint --ext .js *.js
@PHONY: lint

upgrade:
npm -g ls npm-check-updates | grep -c npm-check-updates || npm install -g npm-check-updates
ncu -u
npm install
@PHONY: upgrade
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# mongo-leader

[![Build Status](https://img.shields.io/github/actions/workflow/status/andrewmolyuk/mongo-leader/release.yml)](https://github.com/andrewmolyuk/mongo-leader/actions?query=workflow%3A%22Release+version%22)
[![Build Status](https://img.shields.io/github/actions/workflow/status/andrewmolyuk/mongo-leader/release.yml)](https://github.com/andrewmolyuk/mongo-leader/actions?query=workflow%3A%22Release%22)
[![Dependencies Status](https://badges.depfu.com/badges/63d997d7115c8f3b1c32c570f8941f56/overview.svg)](https://depfu.com/github/andrewmolyuk/mongo-leader?project_id=17960)
[![Codacy Badge](https://img.shields.io/codacy/grade/3b010767baf5402b90ce45239a11d977)](https://www.codacy.com/app/andrewmolyuk/mongo-leader?utm_source=github.com&utm_medium=referral&utm_content=andrewmolyuk/mongo-leader&utm_campaign=Badge_Grade)
[![Maintainability](https://img.shields.io/codeclimate/maintainability/andrewmolyuk/mongo-leader)](https://codeclimate.com/github/andrewmolyuk/mongo-leader/maintainability)
Expand All @@ -20,16 +20,16 @@ npm install mongo-leader
## Example

```javascript
const { Leader } = require("mongo-leader");
const { MongoClient } = require("mongodb");
const { Leader } = require('mongo-leader');
const { MongoClient } = require('mongodb');

const url = "mongodb://localhost:27017";
const url = 'mongodb://localhost:27017';

MongoClient.connect(url, { useNewUrlParser: true }, function (err, client) {
const db = client.db("test");
const db = client.db('test');
const leader = new Leader(db, { ttl: 5000, wait: 1000 });
setInterval(() => {
leader.isLeader().then((leader) => console.log(`Am I leader? : ${leader}`));
leader.isLeader().then(leader => console.log(`Am I leader? : ${leader}`));
}, 100);
});
```
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Leader extends EventEmitter {
{ upsert: true, new: false }
)
.then(result => {
if (result.lastErrorObject.updatedExisting) {
if (result?.lastErrorObject?.updatedExisting) {
setTimeout(() => this.elect(), this.options.wait);
} else {
this.emit('elected');
Expand All @@ -82,7 +82,7 @@ class Leader extends EventEmitter {
{ upsert: false, new: false }
)
.then(result => {
if (result.lastErrorObject.updatedExisting) {
if (result?.lastErrorObject?.updatedExisting) {
setTimeout(() => this.renew(), this.options.ttl / 2);
} else {
this.emit('revoked');
Expand Down
Loading

0 comments on commit 0f90b1f

Please sign in to comment.