Skip to content

Commit

Permalink
dep(redis): v3 -> 4 (#35)
Browse files Browse the repository at this point in the history
* test: drop node 12, add 16
* dep(eslint): bump 7 -> 8
* test: update redis test syntax
  • Loading branch information
msimerson authored May 23, 2022
1 parent 677a154 commit f8c1ee6
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 74 deletions.
2 changes: 1 addition & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
engines:
eslint:
enabled: true
channel: "eslint-6"
channel: "eslint-8"
config:
config: ".eslintrc.yaml"

Expand Down
4 changes: 1 addition & 3 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ env:
node: true
es6: true
mocha: true

parserOptions:
ecmaVersion: 2019
es2020: true

plugins:
- haraka
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: CI Tests

on: [ push ]

env:
CI: true

jobs:

ci-test:
Expand All @@ -16,19 +19,16 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest ]
node-version: [ 12, 14, 16 ]
node-version: [ 14, 16, 18 ]
fail-fast: false

env:
CI: true

steps:
- uses: actions/checkout@v2
name: git checkout
with:
fetch-depth: 1

- uses: actions/setup-node@v2
- uses: actions/setup-node@v3
name: Use Node.js ${{ matrix.node-version }}
with:
node-version: ${{ matrix.node-version }}
Expand Down
13 changes: 6 additions & 7 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: Lint

on: [ push ]

env:
CI: true

jobs:

lint:
Expand All @@ -10,24 +13,20 @@ jobs:

strategy:
matrix:
node-version: [ 14 ]
node-version: [ 16 ]

steps:
- uses: actions/checkout@v2
name: Checkout Code
with:
fetch-depth: 1

- uses: actions/setup-node@v2
- uses: actions/setup-node@v3
name: Use Node.js ${{ matrix.node-version }}
with:
node-version: ${{ matrix.node-version }}

- name: Install
run: npm install
- run: npm install

- name: Lint
run: npm run lint

env:
CI: true
19 changes: 0 additions & 19 deletions .travis.yml

This file was deleted.

18 changes: 17 additions & 1 deletion Changes.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@

## 2.2.0 - 2022-05-23

- dep(node): require 14+
- dep(redis): bump 3 -> 4
- dep(eslint): bump 7 -> 8
- test: update redis test syntax for v4
- doc(README): deprecate usage of 'plugin'
- doc(README): update badges


## 2.1.0 - 2021-10-14

- bump redis dep 2.8.0 -> 3.1.2
Expand All @@ -7,33 +17,39 @@
- use es6 classes
- es6: use "for item of array" syntax for array iterator


## 2.0.3 - 2017-08-26

- add redis_publish boolean to disable redis results publishing


## 2.0.2 - 2017-06-26

- revert #4, until a proper and tested fix is available


## 2.0.1 - 2017-05-26

- eslint 4 compat


## 2.0.0 - 2017-05-26

- Disable Redis pub/sub by default


## 1.0.2 - 2017-02-13

- publish incr operations
- update eslint to inherit eslint-plugin-haraka
- added AppVeyor (windows) testing


## 1.0.1 - 2017-01-26

- update eslint to inherit eslint-plugin-haraka
* depend on haraka-config
* vs ./config, which doesn't work for npm packaged plugin tests

## 1.0.0 - initial release

## 1.0.0 - initial release
40 changes: 19 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,25 @@ Use results in your plugins like so:

```js
exports.my_first_hook = function (next, connection) {
let plugin = this

// run a test
......

// store the results
connection.results.add(plugin, {pass: 'my great test' })
connection.results.add(this, {pass: 'my great test' })

// run another test
.....

// store the results
connection.results.add(plugin, {fail: 'gotcha!', msg: 'show this'})
connection.results.add(this, {fail: 'gotcha!', msg: 'show this'})
}
```

Store the results in the transaction (vs connection):

```js
connection.transaction.results.add(plugin, {...});`
connection.transaction.results.add(this, {...});`
```

### Config options
Expand Down Expand Up @@ -83,18 +82,18 @@ Examples:

```js
const results = connection.results
results.add(plugin, {pass: 'null_sender'})
results.add(plugin, {fail: 'single_recipient'})
results.add(plugin, {skip: 'valid_bounce'}
results.add(plugin, {err: 'timed out looking in couch cushions'})
results.add(plugin, {msg: 'I found a nickel!', emit: true})
results.add(this, {pass: 'null_sender'})
results.add(this, {fail: 'single_recipient'})
results.add(this, {skip: 'valid_bounce'}
results.add(this, {err: 'timed out looking in couch cushions'})
results.add(this, {msg: 'I found a nickel!', emit: true})
```

In addition to appending values to the predefined lists, arbitrary results
can be stored in the cache:

```js
results.add(plugin, {my_result: 'anything I want'})
results.add(this, {my_result: 'anything I want'})
```

When arbirary values are stored, they are listed first in the log output. Their
Expand All @@ -107,10 +106,10 @@ Increment counters. The argument to incr is an object with counter names and
increment values. Examples:

```js
results.incr(plugin, {unrecognized_commands: 1})
results.incr(this, {unrecognized_commands: 1})
results.incr(plugin, {karma: -1})
results.incr(plugin, {karma: 2})
results.incr(this, {karma: -1})
results.incr(this, {karma: 2})
```


Expand All @@ -120,14 +119,14 @@ Append items onto arrays. The argument to push is an object with array names and
the new value to be appended to the array. Examples:

```js
results.push(plugin, {dns_recs: 'name1'})
results.push(plugin, {dns_recs: 'name2'})
results.push(this, {dns_recs: 'name1'})
results.push(this, {dns_recs: 'name2'})
```

#### collate

```js
const summary = results.collate(plugin)
const summary = results.collate(this)
```

Formats the contents of the result cache and returns them. This function is
Expand Down Expand Up @@ -174,8 +173,8 @@ Syntax:
#### Store Results:

```js
results.add(plugin, {pass: 'some_test'})
results.add(plugin, {pass: 'some_test(with reason)'})
results.add(this, {pass: 'some_test'})
results.add(this, {pass: 'some_test(with reason)'})
```

#### Retrieve exact match with **get**:
Expand Down Expand Up @@ -215,7 +214,7 @@ human_html output, prefix the name of the key with an underscore.
Example:

```js
results.add(plugin, { _hidden: 'some data' })
results.add(this, { _hidden: 'some data' })
```

## Redis Pub/Sub
Expand All @@ -237,9 +236,8 @@ exports.register = function (next, server) {
}

exports.redis_subscribe = function (next, connection) {
const plugin = this

plugin.redis_subscribe(connection, function () {
this.redis_subscribe(connection, function () {
connection.notes.redis.on('pmessage', (pattern, channel, message) => {
// do stuff with messages that look like this
// {"plugin":"karma","result":{"fail":"spamassassin.hits"}}
Expand Down
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class ResultStore {
if (!this.conn.server.notes.redis) return;

const channel = `result-${this.conn.transaction ? this.conn.transaction.uuid : this.conn.uuid}`;

this.conn.server.notes.redis.publish(channel, JSON.stringify({ plugin: name, result: obj }));
}

Expand Down
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
{
"name": "haraka-results",
"version": "2.1.0",
"version": "2.2.0",
"description": "Haraka results store for connections and transactions",
"main": "index.js",
"directories": {
"test": "test"
},
"engines": {
"node": ">=14"
},
"scripts": {
"cover": "npx istanbul cover npm run test",
"lint": "npx eslint *.js test/*.js",
"lintfix": "npx eslint --fix *.js test/*.js",
"cover": "npx istanbul cover ./run_tests",
"test": "npx mocha"
},
"repository": {
Expand All @@ -29,16 +32,15 @@
},
"homepage": "https://github.com/haraka/haraka-results#readme",
"devDependencies": {
"eslint": ">=7",
"eslint": ">=8",
"eslint-plugin-haraka": "*",
"haraka-test-fixtures": "*",
"redis": "*",
"mocha": "*"
},
"dependencies": {
"haraka-config": "*"
},
"optionalDependencies": {
"redis": "^3.1.2"
"redis": "^4.1.0"
}
}
20 changes: 9 additions & 11 deletions test/result_store.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,26 +173,24 @@ describe('redis_publish', () => {
redis: require('redis').createClient(),
}
};
await server.notes.redis.connect()
this.connection = new fixtures.connection.createConnection(null, server);
this.connection.results = new Results(this.connection);
})

it('redis_publish', function (done) {
it('redis_publish', async function () {
const conn = this.connection;

// this redis client is subscribed
const sub_db = redis.createClient();
sub_db.on('pmessage', function (pattern, channel, message) {
// console.log(arguments);
const sub_db = redis.createClient()

await sub_db.connect()

await sub_db.pSubscribe('*', (message, channel) => {
assert.equal(JSON.parse(message).result.pass, 'the test');
conn.server.notes.redis.quit()
sub_db.quit()
done()
})
.on('psubscribe', function (pattern, count) {
// console.log(`psubscribed to ${pattern}`);
conn.results.add({ name: 'pi'}, { pass: 'the test'});
})
.psubscribe('*');

conn.results.add({ name: 'pi'}, { pass: 'the test'})
})
})

0 comments on commit f8c1ee6

Please sign in to comment.