-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b2191b
commit 4d47a56
Showing
8 changed files
with
100 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { HEARTBEAT_REQUEST, HEARTBEAT_RESPONSE } from "@src/constants"; | ||
|
||
export function heartbeatRequest(): { | ||
type: "HEARTBEAT_REQUEST"; | ||
} { | ||
return { type: HEARTBEAT_REQUEST }; | ||
} | ||
|
||
export function heartbeatResponse(response: Record<string, any>): { | ||
type: "HEARTBEAT_RESPONSE"; | ||
response: Record<string, any>; | ||
} { | ||
return { type: HEARTBEAT_RESPONSE, response }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { HEARTBEAT_RESPONSE } from "@src/constants"; | ||
import { HeartbeatState } from "@src/types"; | ||
|
||
const INITIAL_STATE: HeartbeatState = { | ||
success: true, | ||
response: {}, | ||
}; | ||
|
||
export default function servers( | ||
state: HeartbeatState = INITIAL_STATE, | ||
action: any | ||
): HeartbeatState { | ||
switch (action.type) { | ||
case HEARTBEAT_RESPONSE: { | ||
return action.response; | ||
} | ||
default: { | ||
return state; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import * as actions from "@src/actions/heartbeat"; | ||
import { getClient } from "@src/client"; | ||
import { ActionType, GetStateFn, SagaGen } from "@src/types"; | ||
import { call, put } from "redux-saga/effects"; | ||
|
||
export function* heartbeatRequest( | ||
getState: GetStateFn, | ||
action: ActionType<typeof actions.heartbeatRequest> | ||
): SagaGen { | ||
const response = yield call(queryHeartbeat); | ||
yield put(actions.heartbeatResponse(response)); | ||
} | ||
|
||
async function queryHeartbeat(): Promise<Record<string, any>> { | ||
const client = getClient(); | ||
|
||
try { | ||
const response: Record<string, any> = await client.execute({ | ||
path: "/__heartbeat__", | ||
headers: undefined, | ||
}); | ||
let success = true; | ||
for (let prop in response) { | ||
if (response[prop] === false) { | ||
success = false; | ||
break; | ||
} | ||
} | ||
return { | ||
success, | ||
response, | ||
}; | ||
} catch (ex) { | ||
return { | ||
success: false, | ||
details: ex, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters