I will post here, yes. Although, again, I do strongly suggest you try it on a staging/test environme
I will post here, yes. Although, again, I do strongly suggest you try it on a staging/test environment first.
WebsiteVerificationReport.create(..) is called, which is the one causing you issues. The error implies that you are passing the wrong argument for c.network connection lost errors, or are you getting internal error errors? Those are two very different things.50 Milliarden which would translate to 50 Billion . Although then English version says 50 Million like pretty much all other resources
Error: D1_ERROR: D1 DB's isolate exceeded its memory limit and was reset. and Error: D1_ERROR: Network connection lost. . I suspect the latter is a symptom of the former. Am I working my DB too hard? DB ID is 1af9dfd0-4a92-4ed3-a17d-f3b09713d888 if that's any use meta object that has this information about rows read and written and query duration itself.internal error errors due to D1 read replication is now fully rolled out in production.wrangler d1 export to create a .sql file and then wrangler d1 execute with that file, but that fails every time due to foreign key constraints.execute command. Any tips?PRAGMA defer_foreign_keys=TRUE; at the topPRAGMA foreign_keys = off; and turn off FKs completely for the duration of the file (then on again at the end)export async function post(c: any, resultCheck?: IWebsiteVerificationReport, db?: any) {
let data;
try {
if (resultCheck?.domain) {
data = resultCheck;
} else {
data = await c.req.json();
}
} catch (error) {
return c.text('Invalid JSON input', 400);
}
if (!data.domain || !data.slug || !data.verification || typeof data.status != 'boolean') {
return new Response('Missing required fields', {status: 400});
// return c.text('Missing required fields', 400);
}
try {
const report = WebsiteVerificationReport.fromObject(data);
const result = await WebsiteVerificationReport.create(report, c, db);
return new Response(`${{ success: true, result }}`, {status: 201})
// return c.json({ success: true, result }, 201);
}
catch (error) {
console.error("Error:", error);
return new Response('Error inserting data into database', {status: 500});
// return c.text("Error inserting data into database", 500);
}
}export const saveReport = async(context: any, data: any, domain: string, db?: any) => {
try {
console.log(JSON.stringify(`App in ctx is ${JSON.stringify(context)}`))
await post(context!, data, db);
} catch (error) {
console.error(error);
return new Response(`Error while managing ckecks for website ${domain}. \n Message: ${error}.`, {status: 500} );
}
}export class RequestQueue {
private queue: Array<any> = [];
private isProcessing = false;
async fetch(request: Request): Promise<Response> {
const { method } = request;
if (method === 'POST') {
const payload = await request.json<LightModeQueueObject>();
console.log(`Received payload: ${JSON.stringify(payload)}`); // Log the payload for debugging
// Validate the payload
if (!payload || !payload.proxyUrl || !payload.data || !payload.bearerToken) {
console.error('Invalid payload:', payload);
return new Response('Invalid payload', { status: 400 });
}
this.queue.push(payload);
this.processQueue();
return new Response('Enqueued');
}
return new Response('Method not allowed', { status: 405 });
}
private async processQueue() {
if (this.isProcessing || this.queue.length === 0) return;
this.isProcessing = true;
const payload = this.queue.shift();
try {
let data;
let result: any = await checkLightMode(payload.proxyUrl, payload.data, payload.bearerToken);
await saveReport(payload.context, data, payload.data.domain.replace('https://', '').replace('http://', ''));
} catch (error) {
console.error(`Error processing payload: ${JSON.stringify(payload)} - ${error}`);
}
}
}const payload: LightModeQueueObject = {
data: config,
proxyUrl: c.env.PROXY_API_URL,
bearerToken: bearerToken,
document: config.document!,
context: c,
db: c.env.DB
}
await queue.fetch('https://dummy-url/queue', { // The url is just a placeholder, it won't be used.
method: 'POST',
body: JSON.stringify(payload),
});network connection lostinternal errorinternal error50 Milliarden50 Billion50 Millionlet db: Kysely<DB>;
export async function getDB() {
if (db) return db;
const d1Binding = await getDatabaseProvider();
db = new Kysely<DB>({
dialect: new D1Dialect({ database: d1Binding }),
});
return db;
}Error: D1_ERROR: D1 DB's isolate exceeded its memory limit and was reset.Error: D1_ERROR: Network connection lost.1af9dfd0-4a92-4ed3-a17d-f3b09713d888wrangler d1 exportexecutePRAGMA defer_foreign_keys=TRUE;PRAGMA foreign_keys = off;