Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#576 Drop dependencies to Primus and Primus plugins #1052

Merged
merged 62 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
b801b71
Update the ws library to 7.4.3
snowteamer Feb 26, 2021
07c3a18
Upload new pubsub utilities
snowteamer Feb 26, 2021
050de89
Update .Gruntfile.babel.js to no longer use Primus
snowteamer Feb 26, 2021
d31d329
Use GIPubSub in backend/index.js
snowteamer Feb 26, 2021
64f8110
Use GIPubSub in backend/server.js
snowteamer Feb 27, 2021
ea427a2
Upload frontend/controller/instance-keys.js
snowteamer Feb 27, 2021
d32a6e2
Use GIPubSub in frontend/main.js
snowteamer Feb 27, 2021
89525b1
Use GIPubSub in frontend/controller/backend.js
snowteamer Feb 27, 2021
cdcd5f1
Use GIPubSub in backend unit tests
snowteamer Feb 27, 2021
a252a57
Drop unused dependencies to Primus and its plugins
snowteamer Feb 27, 2021
36f51c9
Update shared/constants.js to fix a Flow error
snowteamer Feb 27, 2021
49ce90e
Make the pubsub server console output less verbose
snowteamer Feb 27, 2021
0494fa2
Delete unused makeResponse in shared/functions.js
snowteamer Feb 27, 2021
bdf4d75
Remove unreliable remote address logging
snowteamer Feb 28, 2021
f875568
Remove unnecessary option copying
snowteamer Feb 28, 2021
5832b6c
Improve logging of pubsub events and errors
snowteamer Mar 1, 2021
21a55ed
Disable automatic reconnection until it's robust
snowteamer Mar 1, 2021
f0e09d5
Use event names without "on" in event handler maps
snowteamer Mar 1, 2021
e8062be
Comment Flowtype usage in pubsub
snowteamer Mar 3, 2021
9319e03
Fix Flow errors
snowteamer Mar 5, 2021
834b049
Delete unused shared/constants.js
snowteamer Mar 5, 2021
db081e7
Update comments and use more descriptive names
snowteamer Mar 5, 2021
b5ef75a
Update sub() and unsub() methods
snowteamer Mar 7, 2021
e1c343b
Merge branch 'master' of https://github.com/okTurtles/group-income-si…
snowteamer Mar 7, 2021
9256ea3
Fix a type error in notification broadcasting
snowteamer Mar 7, 2021
f8bac19
Move backend/utils/pubsub.js one directory up
snowteamer Mar 8, 2021
9eee8b0
Update reconnection on online events
snowteamer Mar 9, 2021
5f04362
Add .isNew and .shouldReconnect client properties
snowteamer Mar 10, 2021
6176e5e
fixup! Fix a type error in notification broadcasting
snowteamer Mar 10, 2021
1da26fa
Terminate the connection upon invalid messages
snowteamer Mar 12, 2021
42d773d
Add support for the 'manual' createClient() option
snowteamer Mar 12, 2021
8830953
Remove unused isConnecting() and isReconnecting()
snowteamer Mar 12, 2021
e011971
Update the pubsub client's default options
snowteamer Mar 13, 2021
0d55209
Implement the `reconnectOnDisconnection` option
snowteamer Mar 13, 2021
0597595
Add random pubsub client ID to help debugging
snowteamer Mar 14, 2021
6384e26
Implement the maxRetries pubsub client option
snowteamer Mar 16, 2021
174f8d6
Add broadcast() and enumerateSubscribers() methods
snowteamer Mar 17, 2021
8701005
Add broadcast() and enumerateSubscribers() methods
snowteamer Mar 17, 2021
1e8af52
Fix yield-star-spacing lint error
snowteamer Mar 17, 2021
804d892
Fix getNextRandomDelay() and upload unit test file
snowteamer Mar 17, 2021
e7e6969
Define and use a few Flow enum types
snowteamer Mar 17, 2021
771967a
Refactor createNotification() and its callsites
snowteamer Mar 17, 2021
0e4c06f
Optimize serverside SUB and UNSUB message handlers
snowteamer Mar 17, 2021
8bc86b3
Fix lint error
snowteamer Mar 17, 2021
1c9705e
Add 'backend/server/broadcastEntry' sbp selector
snowteamer Mar 17, 2021
52a2d74
Use NOTIFICATION_TYPE.ENTRY instead of 'entry'
snowteamer Mar 17, 2021
5b309b0
Implement ping/pong strategy like in Primus
snowteamer Mar 19, 2021
7b642de
Stop logging 'backend/server/broadcastEntry' calls
snowteamer Mar 19, 2021
0d8e015
Fix failedConnectionAttempts not updating correctly
snowteamer Mar 19, 2021
b90675e
Refactor shared/pubsub.js
snowteamer Mar 19, 2021
77d2f41
Refactor some parts of backend/pubsub.js
snowteamer Mar 21, 2021
bd8344e
Log the number of connections on connection event
snowteamer Mar 23, 2021
640f6f1
Merge branch 'master' of https://github.com/okTurtles/group-income-si…
snowteamer Mar 27, 2021
68545e1
Implement custom reconnection events
snowteamer Apr 1, 2021
3b50fc2
Implement _.randomBytes() and _.randomHexString()
snowteamer Apr 7, 2021
2bb4851
Use SBP selectors for custom pubsub events
snowteamer Apr 7, 2021
36253fb
Refactor message handlers to use `this` less often
snowteamer Apr 7, 2021
e4a2188
Refactor handlers to use fewer `this` bindings
snowteamer Apr 7, 2021
1beb6a1
Document default option values for createServer()
snowteamer Apr 7, 2021
62836da
Move pubsub event constants to shared/pubsub.js
snowteamer Apr 8, 2021
cbc5658
Increase Cypress command timeout from 5s to 10s
snowteamer Apr 8, 2021
29393e6
Pass explicit timeout to createGIPubSubClient()
snowteamer Apr 8, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions .Gruntfile.babel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict'

import sbp from '~/shared/sbp.js'
import resolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'
import alias from 'rollup-plugin-alias'
Expand Down Expand Up @@ -109,14 +108,7 @@ module.exports = (grunt) => {

grunt.registerTask('build', function () {
const rollup = this.flags.watch ? 'rollup:watch' : 'rollup'
if (this.flags.watch) {
// if we are being run with 'grunt dev', tell Primus to generate the file
// ./frontend/controller/utils/primus.js, otherwise, this is 'grunt test', and this
// block will be skipped so that pubsub.js can be required through ./backend/index.js
// TODO: get rid of this when we remove Primus (#576)
require('~/backend/pubsub.js') // hack to register 'backend/pubsub/setup' selector
sbp('backend/pubsub/setup', require('http').createServer(), true)
}
snowteamer marked this conversation as resolved.
Show resolved Hide resolved

if (!grunt.option('skipbuild')) {
grunt.task.run(['exec:eslint', 'exec:flow', 'exec:puglint', 'exec:stylelint', 'copy', rollup])
}
Expand Down Expand Up @@ -256,9 +248,6 @@ module.exports = (grunt) => {
sourcemap: development
},
external: ['crypto'],
moduleContext: {
'frontend/controller/utils/primus.js': 'window'
},
plugins: [
alias({
// https://vuejs.org/v2/guide/installation.html#Standalone-vs-Runtime-only-Build
Expand Down Expand Up @@ -314,7 +303,7 @@ module.exports = (grunt) => {
// NOTE: uncommenting this saves ~1 second off build process
// while making it a massive pain to deal with dependencies
// and causing "ReferenceError: require is not defined"
// include: /(node_modules\/(blakejs|multihashes|tweetnacl|localforage|@babel|vue.+).*|primus\.js$)/,
// include: /(node_modules\/(blakejs|multihashes|tweetnacl|localforage|@babel|vue.+).*)/,
snowteamer marked this conversation as resolved.
Show resolved Hide resolved
namedExports: {
'node_modules/vuelidate/lib/validators/index.js': ['required', 'between', 'email', 'minLength', 'requiredIf'],
'node_modules/emoji-mart-vue-fast/dist/emoji-mart.js': ['Picker', 'EmojiIndex']
Expand Down
6 changes: 3 additions & 3 deletions backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ module.exports = (new Promise((resolve, reject) => {
}): Promise<void>)

const shutdownFn = function (message) {
sbp('okTurtles.data/apply', PUBSUB_INSTANCE, function (primus) {
sbp('okTurtles.data/apply', PUBSUB_INSTANCE, function (pubsub) {
console.log('message received in child, shutting down...', message)
primus.on('close', async function () {
pubsub.on('close', async function () {
try {
await sbp('backend/server/stop')
console.log('Hapi server down')
Expand All @@ -49,7 +49,7 @@ const shutdownFn = function (message) {
process.exit(1)
}
})
primus.destroy({ timeout: 1000 }) // TODO: close: false ?
pubsub.close()
})
}

Expand Down
127 changes: 0 additions & 127 deletions backend/pubsub.js

This file was deleted.

15 changes: 9 additions & 6 deletions backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import './database.js'
import Hapi from '@hapi/hapi'
import GiAuth from './auth.js'
import { GIMessage } from '~/shared/GIMessage.js'
import { makeResponse } from '~/shared/functions.js'
import { RESPONSE_TYPE } from '~/shared/constants.js'
import { SERVER_RUNNING } from './events.js'
import { SERVER_INSTANCE, PUBSUB_INSTANCE } from './instance-keys.js'
import { createMessage, createServer } from './utils/pubsub.js'
import chalk from 'chalk'

const Inert = require('@hapi/inert')
Expand Down Expand Up @@ -45,10 +44,13 @@ sbp('sbp/selectors/register', {
'backend/server/handleEntry': async function (entry: GIMessage) {
const contractID = entry.contractID()
await sbp('gi.db/log/addEntry', entry)
const response = makeResponse(RESPONSE_TYPE.ENTRY, entry.serialize())
console.log(chalk.blue.bold(`broadcasting ${entry.description()}`))
sbp('okTurtles.data/apply', PUBSUB_INSTANCE, p => {
p.room(contractID).write(response)
sbp('okTurtles.data/apply', PUBSUB_INSTANCE, pubsub => {
if (contractID in pubsub.subscribersByContractID) {
snowteamer marked this conversation as resolved.
Show resolved Hide resolved
pubsub.subscribersByContractID[contractID].forEach((client) => {
client.send(createMessage('entry', entry.serialize()))
})
}
snowteamer marked this conversation as resolved.
Show resolved Hide resolved
})
},
'backend/server/stop': function () {
Expand All @@ -62,14 +64,15 @@ if (process.env.NODE_ENV === 'development' && !process.env.CI) {
})
}

sbp('okTurtles.data/set', PUBSUB_INSTANCE, createServer(hapi.listener))

;(async function () {
// https://hapi.dev/tutorials/plugins
await hapi.register([
{ plugin: GiAuth },
{ plugin: Inert }
])
require('./routes.js')
require('./pubsub.js')
await hapi.start()
console.log('Backend server running at:', hapi.info.uri)
sbp('okTurtles.events/emit', SERVER_RUNNING, hapi)
Expand Down
Loading