uhhhh yeah
This commit is contained in:
@@ -116,10 +116,18 @@ export async function postDataToApi(payload: {
|
||||
total,
|
||||
message,
|
||||
);
|
||||
const rj = (await res.json()) as APIRespnose<{
|
||||
let rj:
|
||||
| APIRespnose<{
|
||||
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;
|
||||
userResponseIds.push(
|
||||
...rj.data.bookDtos.map((b) => ({
|
||||
@@ -130,6 +138,8 @@ export async function postDataToApi(payload: {
|
||||
successResponses++;
|
||||
break;
|
||||
}
|
||||
console.log("Failed to send send post request");
|
||||
console.log(res.status, rj);
|
||||
failedResponses++;
|
||||
tries++;
|
||||
}
|
||||
@@ -162,7 +172,8 @@ export async function postDataToApi(payload: {
|
||||
responsesIds.push(...result.value);
|
||||
} else {
|
||||
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(),
|
||||
},
|
||||
body: JSON.stringify({
|
||||
changedBalance,
|
||||
closeTime: draw.closeTime,
|
||||
date: new Date().toISOString().split("T")[0],
|
||||
dealerId,
|
||||
drawId: Number(draw.id.split(":")[1]),
|
||||
closeTime: draw.closeTime,
|
||||
date: new Date().toISOString().split("T")[0],
|
||||
changedBalance,
|
||||
insertData: body,
|
||||
}),
|
||||
});
|
||||
@@ -227,24 +238,31 @@ async function mockSendBatchRequest(
|
||||
changedBalance: number,
|
||||
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
|
||||
await sleep(Math.floor(Math.random() * 1000) + 50);
|
||||
if (Math.random() < 0.005) {
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
code: 500,
|
||||
success: false,
|
||||
message: "Failed",
|
||||
data: {},
|
||||
time: new Date().toISOString(),
|
||||
}),
|
||||
{
|
||||
status: 500,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
statusText: "Failed",
|
||||
},
|
||||
);
|
||||
}
|
||||
// if (Math.random() < 0.005) {
|
||||
// return new Response(
|
||||
// JSON.stringify({
|
||||
// code: 500,
|
||||
// success: false,
|
||||
// message: "Failed",
|
||||
// data: {},
|
||||
// time: new Date().toISOString(),
|
||||
// }),
|
||||
// {
|
||||
// status: 500,
|
||||
// headers: { "Content-Type": "application/json" },
|
||||
// statusText: "Failed",
|
||||
// },
|
||||
// );
|
||||
// }
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
code: 200,
|
||||
@@ -291,10 +309,10 @@ async function deleteAllBookedEntries({
|
||||
"User-Agent": getRandomUserAgent(),
|
||||
},
|
||||
body: JSON.stringify({
|
||||
bookIds: data.map((e) => e.bookId),
|
||||
closeTime,
|
||||
dealerId,
|
||||
drawId,
|
||||
closeTime,
|
||||
bookIds: data.map((e) => e.bookId),
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ export const postDataApiRouter = createTRPCRouter({
|
||||
errors: [],
|
||||
};
|
||||
}
|
||||
console.log(`[=] ${users} users found`);
|
||||
console.log(`[=] ${users.length} users found`);
|
||||
console.log(users);
|
||||
|
||||
console.log("[+] Preparing the sessions for posting");
|
||||
@@ -192,13 +192,15 @@ export const postDataApiRouter = createTRPCRouter({
|
||||
|
||||
console.log(`[+] Posting ${data.length} entries to the API`);
|
||||
|
||||
let ts = new Date().getTime();
|
||||
const res = await postDataToApi({
|
||||
sessions: userSessions,
|
||||
data,
|
||||
users,
|
||||
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) {
|
||||
await removePostSession();
|
||||
|
||||
Reference in New Issue
Block a user