uhhhh yeah
This commit is contained in:
@@ -116,10 +116,18 @@ export async function postDataToApi(payload: {
|
|||||||
total,
|
total,
|
||||||
message,
|
message,
|
||||||
);
|
);
|
||||||
const rj = (await res.json()) as APIRespnose<{
|
let rj:
|
||||||
|
| APIRespnose<{
|
||||||
bookDtos: { bookId: string; requestId: number }[];
|
bookDtos: { bookId: string; requestId: number }[];
|
||||||
}>;
|
}>
|
||||||
if (rj.code === 200 && res.status === 200) {
|
| undefined = undefined;
|
||||||
|
try {
|
||||||
|
rj = (await res.json()) as any;
|
||||||
|
} catch (err) {
|
||||||
|
console.log("Encountered error while parsing post response");
|
||||||
|
console.log(res.status, err);
|
||||||
|
}
|
||||||
|
if (rj && rj.code === 200 && res.status === 200) {
|
||||||
ptr = jumped;
|
ptr = jumped;
|
||||||
userResponseIds.push(
|
userResponseIds.push(
|
||||||
...rj.data.bookDtos.map((b) => ({
|
...rj.data.bookDtos.map((b) => ({
|
||||||
@@ -130,6 +138,8 @@ export async function postDataToApi(payload: {
|
|||||||
successResponses++;
|
successResponses++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
console.log("Failed to send send post request");
|
||||||
|
console.log(res.status, rj);
|
||||||
failedResponses++;
|
failedResponses++;
|
||||||
tries++;
|
tries++;
|
||||||
}
|
}
|
||||||
@@ -162,7 +172,8 @@ export async function postDataToApi(payload: {
|
|||||||
responsesIds.push(...result.value);
|
responsesIds.push(...result.value);
|
||||||
} else {
|
} else {
|
||||||
hasErrors = true;
|
hasErrors = true;
|
||||||
console.log(`[!] Error processing user: ${result.reason}`);
|
console.log(`[!] Error processing user`);
|
||||||
|
console.log(result.reason);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -210,11 +221,11 @@ async function sendBatchRequest(
|
|||||||
"User-Agent": getRandomUserAgent(),
|
"User-Agent": getRandomUserAgent(),
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
changedBalance,
|
|
||||||
closeTime: draw.closeTime,
|
|
||||||
date: new Date().toISOString().split("T")[0],
|
|
||||||
dealerId,
|
dealerId,
|
||||||
drawId: Number(draw.id.split(":")[1]),
|
drawId: Number(draw.id.split(":")[1]),
|
||||||
|
closeTime: draw.closeTime,
|
||||||
|
date: new Date().toISOString().split("T")[0],
|
||||||
|
changedBalance,
|
||||||
insertData: body,
|
insertData: body,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
@@ -227,24 +238,31 @@ async function mockSendBatchRequest(
|
|||||||
changedBalance: number,
|
changedBalance: number,
|
||||||
body: string,
|
body: string,
|
||||||
) {
|
) {
|
||||||
|
console.log("----- Sending batch request ------");
|
||||||
|
console.log(session);
|
||||||
|
console.log(dealerId);
|
||||||
|
console.log(draw);
|
||||||
|
console.log(changedBalance);
|
||||||
|
console.log(body);
|
||||||
|
console.log("----------------------------------");
|
||||||
// between 5 to 20 ms
|
// between 5 to 20 ms
|
||||||
await sleep(Math.floor(Math.random() * 1000) + 50);
|
await sleep(Math.floor(Math.random() * 1000) + 50);
|
||||||
if (Math.random() < 0.005) {
|
// if (Math.random() < 0.005) {
|
||||||
return new Response(
|
// return new Response(
|
||||||
JSON.stringify({
|
// JSON.stringify({
|
||||||
code: 500,
|
// code: 500,
|
||||||
success: false,
|
// success: false,
|
||||||
message: "Failed",
|
// message: "Failed",
|
||||||
data: {},
|
// data: {},
|
||||||
time: new Date().toISOString(),
|
// time: new Date().toISOString(),
|
||||||
}),
|
// }),
|
||||||
{
|
// {
|
||||||
status: 500,
|
// status: 500,
|
||||||
headers: { "Content-Type": "application/json" },
|
// headers: { "Content-Type": "application/json" },
|
||||||
statusText: "Failed",
|
// statusText: "Failed",
|
||||||
},
|
// },
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
return new Response(
|
return new Response(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
code: 200,
|
code: 200,
|
||||||
@@ -291,10 +309,10 @@ async function deleteAllBookedEntries({
|
|||||||
"User-Agent": getRandomUserAgent(),
|
"User-Agent": getRandomUserAgent(),
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
|
bookIds: data.map((e) => e.bookId),
|
||||||
|
closeTime,
|
||||||
dealerId,
|
dealerId,
|
||||||
drawId,
|
drawId,
|
||||||
closeTime,
|
|
||||||
bookIds: data.map((e) => e.bookId),
|
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ export const postDataApiRouter = createTRPCRouter({
|
|||||||
errors: [],
|
errors: [],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
console.log(`[=] ${users} users found`);
|
console.log(`[=] ${users.length} users found`);
|
||||||
console.log(users);
|
console.log(users);
|
||||||
|
|
||||||
console.log("[+] Preparing the sessions for posting");
|
console.log("[+] Preparing the sessions for posting");
|
||||||
@@ -192,13 +192,15 @@ export const postDataApiRouter = createTRPCRouter({
|
|||||||
|
|
||||||
console.log(`[+] Posting ${data.length} entries to the API`);
|
console.log(`[+] Posting ${data.length} entries to the API`);
|
||||||
|
|
||||||
|
let ts = new Date().getTime();
|
||||||
const res = await postDataToApi({
|
const res = await postDataToApi({
|
||||||
sessions: userSessions,
|
sessions: userSessions,
|
||||||
data,
|
data,
|
||||||
users,
|
users,
|
||||||
draw,
|
draw,
|
||||||
});
|
});
|
||||||
console.timeEnd("Time taken to post data to the API");
|
let done = new Date().getTime();
|
||||||
|
console.log(`Time taken to post data to the API: ${done - ts} ms`);
|
||||||
|
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
await removePostSession();
|
await removePostSession();
|
||||||
|
|||||||
Reference in New Issue
Block a user