Skip to content

Commit

Permalink
Merge pull request #1 from codibre/fix-redis-error
Browse files Browse the repository at this point in the history
fix: wrapping redis to avoid erros when redis is not available
  • Loading branch information
Farenheith authored Nov 13, 2023
2 parents 98b0999 + 3143a46 commit 8aaba24
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 695 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/semantic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: semantic-release

on:
push:
branches: [master]

jobs:
semantic:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
NPM_TOKEN: ${{secrets.NPM_TOKEN}}
HUSKY: 0
CI: true
steps:
- uses: actions/checkout@master
with:
token: ${{ secrets.GH_TOKEN }}
- uses: actions/setup-node@v3
with:
node-version: "16.x"
- run: printf "//`node -p \"require('url').parse('https://registry.npmjs.org').host\"`/:_authToken=${NPM_TOKEN}\n" >> ~/.npmrc
- run: npm ci
- run: npm run test
- uses: actions/setup-node@v3
with:
node-version: "lts/*"
- run: previousVersion=$(sed 's/.*"version": "\(.*\)".*/\1/;t;d' ./package.json)
- run: npm i -g @semantic-release/changelog @semantic-release/commit-analyzer @semantic-release/git @semantic-release/github @semantic-release/exec @semantic-release/npm @semantic-release/release-notes-generator semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
NPM_TOKEN: ${{secrets.NPM_TOKEN}}
HUSKY: 0
CI: true
- run: npx semantic-release --ci
- run: finalVersion=$(sed 's/.*"version": "\(.*\)".*/\1/;t;d' ./package.json)
- run: |
if [ "$previousVersion" != "$finalVersion" ]; then
git push
fi
env:
NPM_TOKEN: ${{secrets.NPM_TOKEN}}
14 changes: 14 additions & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"branches": [
"main"
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/changelog",
"@semantic-release/release-notes-generator",
"@semantic-release/npm",
"@semantic-release/github",
"@semantic-release/git"
],
"preset": "angular"
}
16 changes: 14 additions & 2 deletions lib/winston-redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ const Transport = require('winston-transport');
const Stream = require('stream').Stream;
const async = require('async');
const _ = require('lodash');
let getSafeInstance;

function wrapRedis(redis) {
if (process.version >= 'v16') {
if (!getSafeInstance) {
getSafeInstance = require('get-safe-instance').getSafeInstance;
}
return getSafeInstance(redis, 5000, ['auth', 'lpush', 'ltrim', 'publish', 'lrange']);
}

return redis;
}

// TODO REMOVE WHEN FIXED
const { normalizeQuery, formatResults } = require('./transport-patch.js');
Expand All @@ -30,12 +42,12 @@ class Redis extends Transport {
if (options.redis instanceof redis.RedisClient) {
this.redis = options.redis;
} else if (options.redis instanceof Object) {
this.redis = redis.createClient(options.redis);
this.redis = wrapRedis(redis.createClient(options.redis))
this.createdClient = true;
} else {
options.host = options.host || 'localhost';
options.port = options.port || 6379;
this.redis = redis.createClient(options.port, options.host);
this.redis = wrapRedis(redis.createClient(options.port, options.host));
this.createdClient = true;
}

Expand Down
Loading

0 comments on commit 8aaba24

Please sign in to comment.