-
Notifications
You must be signed in to change notification settings - Fork 15
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
Socket Initialization on user login #1109
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// TODO remove dependency from the store when the fixme is fixed | ||
import { updateLastExecution } from '@state/actions/lastExecutions'; | ||
import { joinChannel } from '@lib/network/socket'; | ||
|
||
const registerEvents = (store, socket, channelName, events) => { | ||
const channel = socket.channel(channelName, {}); | ||
|
||
events.forEach((event) => { | ||
channel.on(event, (payload) => | ||
store.dispatch({ type: event.toUpperCase(), payload }) | ||
); | ||
}); | ||
|
||
joinChannel(channel); | ||
}; | ||
|
||
const processChannelEvents = (reduxStore, socket) => { | ||
registerEvents(reduxStore, socket, 'monitoring:hosts', [ | ||
'host_registered', | ||
'host_details_updated', | ||
'heartbeat_succeded', | ||
'heartbeat_failed', | ||
]); | ||
registerEvents(reduxStore, socket, 'monitoring:clusters', [ | ||
'cluster_registered', | ||
'cluster_details_updated', | ||
'checks_execution_started', | ||
'checks_execution_completed', | ||
'checks_results_updated', | ||
'cluster_health_changed', | ||
'cluster_cib_last_written_updated', | ||
]); | ||
registerEvents(reduxStore, socket, 'monitoring:sap_systems', [ | ||
'sap_system_registered', | ||
'sap_system_health_changed', | ||
'application_instance_registered', | ||
'application_instance_health_changed', | ||
]); | ||
registerEvents(reduxStore, socket, 'monitoring:databases', [ | ||
'database_registered', | ||
'database_health_changed', | ||
'database_instance_registered', | ||
'database_instance_health_changed', | ||
'database_instance_system_replication_changed', | ||
]); | ||
|
||
// FIXME: This is to overcome the fact that we are generating names with registerEvents | ||
// in the future we want to remove this and use the constants directly, | ||
// since events and actions may have different names and parameters. | ||
const channel = socket.channel('monitoring:executions', {}); | ||
channel.on('execution_completed', ({ group_id: groupID }) => { | ||
reduxStore.dispatch(updateLastExecution(groupID)); | ||
}); | ||
|
||
joinChannel(channel); | ||
}; | ||
|
||
export default processChannelEvents; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,6 +96,9 @@ import { | |
|
||
import { CHECKS_SELECTED } from '@state/actions/cluster'; | ||
import { EXECUTION_REQUESTED } from '@state/actions/lastExecutions'; | ||
import { initSocketConnection } from '@lib/network/socket'; | ||
import processChannelEvents from '@state/channels'; | ||
import { store } from '@state'; | ||
|
||
const notify = ({ text, icon }) => ({ | ||
type: 'NOTIFICATION', | ||
|
@@ -154,8 +157,16 @@ function* initialDataFetch() { | |
yield put(stopDatabasesLoading()); | ||
} | ||
|
||
function* watchInitialDataFetching() { | ||
yield takeLatest('user/setUserAsLogged', initialDataFetch); | ||
function* setupSocketEvents() { | ||
const socket = initSocketConnection(); | ||
yield call(processChannelEvents, store, socket); | ||
} | ||
|
||
function* watchUserLoggedIn() { | ||
yield all([ | ||
takeLatest('user/setUserAsLogged', initialDataFetch), | ||
takeLatest('user/setUserAsLogged', setupSocketEvents), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if this breaks? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The application will crash, it's an unrecoverable error (no sockets no frontend basically), for the initial data fetching the error handling is the same as all the api requests |
||
]); | ||
} | ||
|
||
function* watchResetState() { | ||
|
@@ -637,7 +648,7 @@ function* watchClustrConnectionSettings() { | |
|
||
export default function* rootSaga() { | ||
yield all([ | ||
watchInitialDataFetching(), | ||
watchUserLoggedIn(), | ||
watchResetState(), | ||
watchHostRegistered(), | ||
watchHostDetailsUpdated(), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't the linter catch this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was a formatting issue, for some reason previous formatting tasks didn't catch 🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CDimonaco can we investigate? are we checking the formatting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes in the CI we have the correct step, I will investigate further.