Update logging
This commit is contained in:
parent
def602c05e
commit
810a333429
39 changed files with 85 additions and 139 deletions
|
|
@ -6,7 +6,7 @@ const __filename = fileURLToPath(import.meta.url);
|
|||
const __dirname = path.dirname(__filename);
|
||||
|
||||
const startWorker = async () => {
|
||||
console.log("Starting worker...");
|
||||
console.info("Starting worker...");
|
||||
|
||||
await run({
|
||||
connectionString: process.env.DATABASE_URL,
|
||||
|
|
|
|||
|
|
@ -62,9 +62,8 @@ export const createZammadTicket = async (
|
|||
},
|
||||
});
|
||||
} catch (error: any) {
|
||||
console.log(Object.keys(error));
|
||||
if (error.isBoom) {
|
||||
console.log(error.output);
|
||||
console.error(error.output);
|
||||
throw new Error("Failed to create zamamd ticket");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ const defaultAudioConvertOpts = {
|
|||
**/
|
||||
export const convert = (
|
||||
input: Buffer,
|
||||
opts?: AudioConvertOpts
|
||||
opts?: AudioConvertOpts,
|
||||
): Promise<Buffer> => {
|
||||
const settings = { ...defaultAudioConvertOpts, ...opts };
|
||||
return new Promise((resolve, reject) => {
|
||||
|
|
@ -35,12 +35,8 @@ export const convert = (
|
|||
.audioCodec(settings.audioCodec)
|
||||
.audioBitrate(settings.bitrate)
|
||||
.toFormat(settings.format)
|
||||
.on("error", (err, stdout, stderr) => {
|
||||
.on("error", (err, _stdout, _stderr) => {
|
||||
console.error(err.message);
|
||||
console.log("FFMPEG OUTPUT");
|
||||
console.log(stdout);
|
||||
console.log("FFMPEG ERROR");
|
||||
console.log(stderr);
|
||||
reject(err);
|
||||
})
|
||||
.on("end", () => {
|
||||
|
|
@ -66,8 +62,12 @@ export const selfCheck = (): Promise<boolean> => {
|
|||
resolve(false);
|
||||
}
|
||||
|
||||
const preds = R.map(requiredCodecs, (codec) => (available: any) =>
|
||||
available[codec] && available[codec].canDemux && available[codec].canMux
|
||||
const preds = R.map(
|
||||
requiredCodecs,
|
||||
(codec) => (available: any) =>
|
||||
available[codec] &&
|
||||
available[codec].canDemux &&
|
||||
available[codec].canMux,
|
||||
);
|
||||
|
||||
resolve(R.allPass(codecs, preds));
|
||||
|
|
@ -79,6 +79,6 @@ export const assertFfmpegAvailable = async (): Promise<void> => {
|
|||
const r = await selfCheck();
|
||||
if (!r)
|
||||
throw new Error(
|
||||
`ffmpeg is not installed, could not be located, or does not support the required codecs: ${requiredCodecs}`
|
||||
`ffmpeg is not installed, could not be located, or does not support the required codecs: ${requiredCodecs}`,
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -19,13 +19,11 @@ const notifyWebhooksTask = async (
|
|||
for (const webhook of webhooks) {
|
||||
const { endpointUrl, httpMethod, headers } = webhook;
|
||||
const finalHeaders = { "Content-Type": "application/json", ...headers };
|
||||
console.log({ endpointUrl, httpMethod, headers, finalHeaders });
|
||||
const result = await fetch(endpointUrl, {
|
||||
method: httpMethod,
|
||||
headers: finalHeaders,
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
console.log(result);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ const sendFacebookMessageTask = async (
|
|||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(outgoingMessage),
|
||||
});
|
||||
console.log({ response });
|
||||
} catch (error) {
|
||||
console.error({ error });
|
||||
throw error;
|
||||
|
|
|
|||
|
|
@ -46,7 +46,6 @@ const processMessage = async ({
|
|||
message: msg,
|
||||
}: ProcessMessageArgs): Promise<Record<string, any>[]> => {
|
||||
const { envelope } = msg;
|
||||
console.log(envelope);
|
||||
const { source, sourceUuid, dataMessage } = envelope;
|
||||
|
||||
if (!dataMessage) return [];
|
||||
|
|
@ -125,7 +124,6 @@ const fetchSignalMessagesTask = async ({
|
|||
phoneNumber,
|
||||
message,
|
||||
});
|
||||
console.log({ formattedMessages });
|
||||
for (const formattedMessage of formattedMessages) {
|
||||
if (formattedMessage.to !== formattedMessage.from) {
|
||||
await worker.addJob(
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@ const getZammadTickets = async (
|
|||
{ headers },
|
||||
);
|
||||
const tickets: any = await rawTickets.json();
|
||||
console.log({ tickets });
|
||||
if (!tickets || tickets.length === 0) {
|
||||
return [shouldContinue, docs];
|
||||
}
|
||||
|
|
@ -49,23 +48,9 @@ const getZammadTickets = async (
|
|||
shouldContinue = true;
|
||||
|
||||
if (source_closed_at <= minUpdatedTimestamp) {
|
||||
console.log(`Skipping ticket`, {
|
||||
source_id,
|
||||
source_updated_at,
|
||||
source_closed_at,
|
||||
minUpdatedTimestamp,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
console.log(`Processing ticket`, {
|
||||
source_id,
|
||||
source_updated_at,
|
||||
source_closed_at,
|
||||
minUpdatedTimestamp,
|
||||
});
|
||||
|
||||
const rawArticles = await fetch(
|
||||
const rawArticles = await fetch(
|
||||
`${zammadApiUrl}/ticket_articles/by_ticket/${source_id}`,
|
||||
{ headers },
|
||||
);
|
||||
|
|
@ -178,8 +163,6 @@ const sendToLabelStudio = async (tickets: FormattedZammadTicket[]) => {
|
|||
body: JSON.stringify([ticket]),
|
||||
});
|
||||
const importResult = await res.json();
|
||||
|
||||
console.log(JSON.stringify(importResult, undefined, 2));
|
||||
}
|
||||
};
|
||||
*/
|
||||
|
|
@ -201,7 +184,6 @@ const importLabelStudioTask = async (): Promise<void> => {
|
|||
await sendToLabelStudio(tickets);
|
||||
const lastTicket = tickets.pop();
|
||||
const newLastTimestamp = lastTicket.data.source_closed_at;
|
||||
console.log({ newLastTimestamp });
|
||||
await db.settings.upsert(settingName, {
|
||||
minUpdatedTimestamp: newLastTimestamp,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -43,14 +43,11 @@ const getLabelStudioTickets = async (
|
|||
page_size: "50",
|
||||
page: `${page}`,
|
||||
});
|
||||
console.log({ url: `${labelStudioApiUrl}/projects/1/tasks?${ticketsQuery}` });
|
||||
const res = await fetch(
|
||||
`${labelStudioApiUrl}/projects/1/tasks?${ticketsQuery}`,
|
||||
{ headers },
|
||||
);
|
||||
console.log({ res });
|
||||
const tasksResult: any = await res.json();
|
||||
console.log({ tasksResult });
|
||||
|
||||
return tasksResult;
|
||||
};
|
||||
|
|
@ -63,14 +60,11 @@ const fetchFromLabelStudio = async (
|
|||
|
||||
for await (const page of pages) {
|
||||
const docs = await getLabelStudioTickets(page + 1);
|
||||
console.log({ page, docs });
|
||||
|
||||
if (docs && docs.length > 0) {
|
||||
for (const doc of docs) {
|
||||
const updatedAt = new Date(doc.updated_at);
|
||||
console.log({ updatedAt, minUpdatedTimestamp });
|
||||
if (updatedAt > minUpdatedTimestamp) {
|
||||
console.log(`Adding doc`, { doc });
|
||||
allDocs.push(doc);
|
||||
}
|
||||
}
|
||||
|
|
@ -79,7 +73,6 @@ const fetchFromLabelStudio = async (
|
|||
}
|
||||
}
|
||||
|
||||
console.log({ allDocs });
|
||||
return allDocs;
|
||||
};
|
||||
|
||||
|
|
@ -93,9 +86,7 @@ const sendToLeafcutter = async (tickets: LabelStudioTicket[]) => {
|
|||
},
|
||||
} = config;
|
||||
|
||||
console.log({ tickets });
|
||||
const filteredTickets = tickets.filter((ticket) => ticket.is_labeled);
|
||||
console.log({ filteredTickets });
|
||||
const finalTickets: LeafcutterTicket[] = filteredTickets.map((ticket) => {
|
||||
const {
|
||||
id,
|
||||
|
|
@ -131,8 +122,7 @@ const sendToLeafcutter = async (tickets: LabelStudioTicket[]) => {
|
|||
};
|
||||
});
|
||||
|
||||
console.log("Sending to Leafcutter");
|
||||
console.log({ finalTickets });
|
||||
console.info("Sending to Leafcutter");
|
||||
|
||||
const result = await fetch(opensearchApiUrl, {
|
||||
method: "POST",
|
||||
|
|
@ -157,15 +147,7 @@ const importLeafcutterTask = async (): Promise<void> => {
|
|||
? new Date(res.value.minUpdatedTimestamp as string)
|
||||
: new Date("2023-03-01");
|
||||
const newLastTimestamp = new Date();
|
||||
console.log({
|
||||
contributorName,
|
||||
settingName,
|
||||
res,
|
||||
startTimestamp,
|
||||
newLastTimestamp,
|
||||
});
|
||||
const tickets = await fetchFromLabelStudio(startTimestamp);
|
||||
console.log({ tickets });
|
||||
await sendToLeafcutter(tickets);
|
||||
await db.settings.upsert(settingName, {
|
||||
minUpdatedTimestamp: newLastTimestamp,
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ const receiveSignalMessageTask = async ({
|
|||
filename,
|
||||
mimeType,
|
||||
}: ReceiveSignalMessageTaskOptions): Promise<void> => {
|
||||
console.log({ token, to, from });
|
||||
const worker = await getWorkerUtils();
|
||||
const row = await db
|
||||
.selectFrom("SignalBot")
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ const sendSignalMessageTask = async ({
|
|||
to,
|
||||
message,
|
||||
}: SendSignalMessageTaskOptions): Promise<void> => {
|
||||
console.log({ token, to });
|
||||
const bot = await db
|
||||
.selectFrom("SignalBot")
|
||||
.selectAll()
|
||||
|
|
@ -34,7 +33,6 @@ const sendSignalMessageTask = async ({
|
|||
message,
|
||||
},
|
||||
});
|
||||
console.log({ response });
|
||||
} catch (error) {
|
||||
console.error({ error });
|
||||
throw error;
|
||||
|
|
|
|||
|
|
@ -23,8 +23,6 @@ const receiveWhatsappMessageTask = async ({
|
|||
filename,
|
||||
mimeType,
|
||||
}: ReceiveWhatsappMessageTaskOptions): Promise<void> => {
|
||||
console.log({ token, to, from });
|
||||
|
||||
const worker = await getWorkerUtils();
|
||||
const row = await db
|
||||
.selectFrom("WhatsappBot")
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ const sendWhatsappMessageTask = async ({
|
|||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(params),
|
||||
});
|
||||
console.log({ result });
|
||||
} catch (error) {
|
||||
console.error({ error });
|
||||
throw new Error("Failed to send message");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue