Skip to content

Commit

Permalink
* Fixed test cases.
Browse files Browse the repository at this point in the history
* Code cleanup - simple func for displaying elapsed time instead of 3 bundled modules.
* Code cleanup - redundant modules cleanup.
* Code cleanup - redundant promises removed.
  • Loading branch information
orbitlens committed Feb 17, 2020
1 parent 086c1dd commit 93aa567
Show file tree
Hide file tree
Showing 18 changed files with 409 additions and 411 deletions.
13 changes: 13 additions & 0 deletions HISTORY.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
0.4.2 / 2020-02-16
==================

* Fixed test cases.
* Code cleanup - simple func for displaying elapsed time instead of 3 bundled modules.
* Code cleanup - redundant modules cleanup.
* Code cleanup - redundant promises removed.

0.4.1 / 2020-02-16
==================

* Updated live stream listening routine to address Horizon throttling.

0.4.0 / 2020-02-16
==================

Expand Down
2 changes: 0 additions & 2 deletions api/authorization-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,8 @@ function userMiddleware(req, res, next) {
pubkey: user.pubkey,
roles: user.roles
}
return Promise.resolve()
})
}
return Promise.resolve()
})
.then(next)
}
Expand Down
4 changes: 2 additions & 2 deletions api/observer-routes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const pkgInfo = require('../package'),
{signer} = require('../util/signer'),
observer = require('../logic/observer'),
moment = require('moment-timezone'),
{elapsed} = require('../util/elapsed-time'),
auth = require('./authorization-handler'),
roles = require('../models/user/roles')

Expand Down Expand Up @@ -35,7 +35,7 @@ module.exports = function (app) {
//get application status
app.get('/api/status', (req, res) => res.json({
version: pkgInfo.version,
uptime: moment.duration(new Date() - started, 'milliseconds').format(),
uptime: elapsed(new Date(), started),
publicKey: signer.getPublicKey()
}))

Expand Down
21 changes: 10 additions & 11 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,28 @@ function init() {
const observer = require('./logic/observer')
observer.start()

//setup moment formatting extension
require('moment-duration-format')(require('moment-timezone'))

//init HTTP server and map all API routes
const server = require('./api/server-initialization')(config)

//TODO: implement graceful observer finalization on OS kill signal

function shutdown() {
console.log('Received kill signal');
console.log('Received kill signal')
server.close(() => {
console.log('Closed out remaining connections');
process.exit(0);
});
console.log('Closed out remaining connections')
process.exit(0)
})

setTimeout(() => {
console.error('Could not close connections in time, forcefully shutting down');
process.exit(1);
}, 10000);
console.error('Could not close connections in time, forcefully shutting down')
process.exit(1)
}, 10000)
}

server.shutdown = shutdown

return Promise.resolve(server)
return server
})
}

module.exports = init()
2 changes: 1 addition & 1 deletion logic/notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Notifier {
if (!notification) {
subscription.processed = true //no more notifications available, set "processed" flag
this.inProgress.delete(subscription.id)
return Promise.resolve()
return
}
return this.sendNotification(notification, subscription)
.then(() => {
Expand Down
1 change: 1 addition & 0 deletions logic/observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Observer {
this.__loadingSubscriptionPromise = storage.fetchSubscriptions()
.then(fetched => {
this.subscriptions = fetched || []
this.__loadingSubscriptionPromise = undefined
return this.subscriptions
})
return this.__loadingSubscriptionPromise
Expand Down
89 changes: 32 additions & 57 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@stellar-expert/operations-notifier",
"license": "MIT",
"private": true,
"version": "0.4.0",
"version": "0.4.2",
"author": "orbitlens<[email protected]>",
"description": "Stellar operations observer and notifier.",
"main": "app.js",
Expand All @@ -11,10 +11,15 @@
"type": "git",
"url": "https://github.com/orbitlens/stellar-notifier"
},
"bugs": {
"url": "https://github.com/orbitlens/stellar-notifier/issues",
"email": "[email protected]"
},
"scripts": {
"dev": "cross-env NODE_ENV=development node ./app.js",
"start": "cross-env NODE_ENV=production node ./app.js",
"test": "cross-env NODE_ENV=test node_modules/.bin/mocha"
"test": "cross-env NODE_ENV=test node_modules/.bin/mocha",
"preversion": "npm test"
},
"keywords": [
"stellar",
Expand All @@ -30,16 +35,14 @@
"cross-env": "^7.0.0",
"cors": "^2.8.5",
"express": "^4.17.1",
"moment-duration-format": "^2.3.2",
"moment-timezone": "^0.5.27",
"mongoose": "^5.9.1",
"stellar-sdk": "^4.0.0",
"throttleit": "^1.0.0",
"uuid": "^3.4.0"
},
"devDependencies": {
"chai": "^4.2.0",
"chai-http": "^4.2.0",
"chai-http": "^4.3.0",
"mocha": "^7.0.1",
"morgan": "^1.9.1",
"sinon": "^8.1.1"
Expand Down
6 changes: 3 additions & 3 deletions persistence-layer/memory-storage-provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class MemoryStorageProvider extends StorageProvider {
constructor() {
super()
}

init(config) {
return Promise.resolve()
}
Expand Down Expand Up @@ -50,15 +50,15 @@ class MemoryStorageProvider extends StorageProvider {

removeNotification(notification) {
ensureId(notification)
let index = repository.notifications.indexOf(notification)
const index = repository.notifications.indexOf(notification)
if (index >= 0) {
repository.notifications.splice(index, 1)
}
return Promise.resolve(notification)
}

markAsProcessed(notification, subscription) {
let pos = notification.subscriptions.indexOf(subscription.id)
const pos = notification.subscriptions.indexOf(subscription.id)
if (pos >= 0) {
notification.subscriptions.splice(pos, 1)
}
Expand Down
Loading

0 comments on commit 93aa567

Please sign in to comment.