Skip to content

Commit 4a4d76f

Browse files
AUTH-165 | Remove serverValidityPeriod check and add a ttl on redis response lpush
1 parent a96a2fc commit 4a4d76f

3 files changed

Lines changed: 31 additions & 30 deletions

File tree

js/lib/request_response/index.js

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/lib/request_response/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ts/lib/request_response/index.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,11 @@ export function request<T>(redisClient, channel: string, body: any, requestValid
7878
}
7979

8080
export async function server<T, S>(redisClient, channel: string, callback: serverCallback<T, S>, serverValidityPeriod: number): Promise<void> {
81+
const REDIS_RESPONSE_TTL_IN_SECONDS = 1
8182
const clientClone = redisClient.duplicate()
8283
clients.push(clientClone)
8384

84-
function brpop () {
85+
function brpop() {
8586
clientClone.brpop(channel, 0, async function (_null, popInfo) {
8687
if (_null) {
8788
console.error('BRPOP ERROR', _null)
@@ -100,35 +101,35 @@ export async function server<T, S>(redisClient, channel: string, callback: serve
100101
const req: EpicurusRequest = JSON.parse(rawRequest)
101102
req.body.channel = channel
102103

103-
if (req.ttl > Date.now() - serverValidityPeriod) {
104-
callback(req.body, async function (error, result) {
105-
const errorRef = error
106-
? { name: error.name, message: error.message, stack: error.stack, severity: error.severity || 1, status: error.status }
107-
: null
104+
callback(req.body, async function (error, result) {
105+
const errorRef = error
106+
? { name: error.name, message: error.message, stack: error.stack, severity: error.severity || 1, status: error.status }
107+
: null
108108

109-
let redisResponse: EpicurusResponse = {
110-
error: errorRef,
111-
result: result
112-
}
109+
let redisResponse: EpicurusResponse = {
110+
error: errorRef,
111+
result: result
112+
}
113+
114+
redisClient.lpush(req.reqId, JSON.stringify(redisResponse))
115+
redisClient.expire(req.reqId, REDIS_RESPONSE_TTL_IN_SECONDS)
116+
})
113117

114-
redisClient.lpush(req.reqId, JSON.stringify(redisResponse))
115-
})
116-
}
117118
})
118119
}
119120

120121
brpop()
121122
}
122123

123-
export function disableServers () {
124+
export function disableServers() {
124125
serversEnabled = false
125126
closeAllClients()
126127
}
127128

128-
export function enableServers () {
129+
export function enableServers() {
129130
serversEnabled = true
130131
}
131132

132-
export function closeAllClients () {
133+
export function closeAllClients() {
133134
clients.forEach(c => c.end(false))
134135
}

0 commit comments

Comments
 (0)