chore: code cleanup
This commit is contained in:
@@ -36,8 +36,6 @@ export function saveIntegrations(fileName: string, integrations: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function updateGoogleSheet(robotId: string, runId: string) {
|
export async function updateGoogleSheet(robotId: string, runId: string) {
|
||||||
console.log(`Starting updateGoogleSheet for robotId: ${robotId}, runId: ${runId}`);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const run = await Run.findOne({ where: { runId } });
|
const run = await Run.findOne({ where: { runId } });
|
||||||
|
|
||||||
@@ -49,10 +47,8 @@ export async function updateGoogleSheet(robotId: string, runId: string) {
|
|||||||
|
|
||||||
if (plainRun.status === 'success' && plainRun.serializableOutput) {
|
if (plainRun.status === 'success' && plainRun.serializableOutput) {
|
||||||
const data = plainRun.serializableOutput['item-0'] as { [key: string]: any }[];
|
const data = plainRun.serializableOutput['item-0'] as { [key: string]: any }[];
|
||||||
console.log('Serializable output data:', data);
|
|
||||||
|
|
||||||
const robot = await Robot.findOne({ where: { 'recording_meta.id': robotId } });
|
const robot = await Robot.findOne({ where: { 'recording_meta.id': robotId } });
|
||||||
console.log('Robot found:', robot);
|
|
||||||
|
|
||||||
if (!robot) {
|
if (!robot) {
|
||||||
throw new Error(`Robot not found for robotId: ${robotId}`);
|
throw new Error(`Robot not found for robotId: ${robotId}`);
|
||||||
@@ -67,8 +63,6 @@ export async function updateGoogleSheet(robotId: string, runId: string) {
|
|||||||
const headers = Object.keys(data[0]);
|
const headers = Object.keys(data[0]);
|
||||||
const rows = data.map((row: { [key: string]: any }) => Object.values(row));
|
const rows = data.map((row: { [key: string]: any }) => Object.values(row));
|
||||||
const outputData = [headers, ...rows];
|
const outputData = [headers, ...rows];
|
||||||
|
|
||||||
console.log('Data to be written to sheet:', outputData);
|
|
||||||
|
|
||||||
await writeDataToSheet(robotId, spreadsheetId, outputData);
|
await writeDataToSheet(robotId, spreadsheetId, outputData);
|
||||||
console.log(`Data written to Google Sheet successfully for Robot: ${robotId} and Run: ${runId}`);
|
console.log(`Data written to Google Sheet successfully for Robot: ${robotId} and Run: ${runId}`);
|
||||||
@@ -83,7 +77,6 @@ export async function updateGoogleSheet(robotId: string, runId: string) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export async function writeDataToSheet(robotId: string, spreadsheetId: string, data: any[]) {
|
export async function writeDataToSheet(robotId: string, spreadsheetId: string, data: any[]) {
|
||||||
try {
|
try {
|
||||||
const robot = await Robot.findOne({ where: { 'recording_meta.id': robotId } });
|
const robot = await Robot.findOne({ where: { 'recording_meta.id': robotId } });
|
||||||
@@ -109,9 +102,7 @@ export async function writeDataToSheet(robotId: string, spreadsheetId: string, d
|
|||||||
refresh_token: plainRobot.google_refresh_token,
|
refresh_token: plainRobot.google_refresh_token,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Log tokens and any refresh activity
|
|
||||||
oauth2Client.on('tokens', async (tokens) => {
|
oauth2Client.on('tokens', async (tokens) => {
|
||||||
console.log('OAuth2 tokens updated:', tokens);
|
|
||||||
if (tokens.refresh_token) {
|
if (tokens.refresh_token) {
|
||||||
await robot.update({ google_refresh_token: tokens.refresh_token });
|
await robot.update({ google_refresh_token: tokens.refresh_token });
|
||||||
}
|
}
|
||||||
@@ -124,7 +115,6 @@ export async function writeDataToSheet(robotId: string, spreadsheetId: string, d
|
|||||||
|
|
||||||
const resource = { values: data };
|
const resource = { values: data };
|
||||||
console.log('Attempting to write to spreadsheet:', spreadsheetId);
|
console.log('Attempting to write to spreadsheet:', spreadsheetId);
|
||||||
console.log('Data being written:', data);
|
|
||||||
|
|
||||||
const response = await sheets.spreadsheets.values.append({
|
const response = await sheets.spreadsheets.values.append({
|
||||||
spreadsheetId,
|
spreadsheetId,
|
||||||
@@ -133,8 +123,6 @@ export async function writeDataToSheet(robotId: string, spreadsheetId: string, d
|
|||||||
requestBody: resource,
|
requestBody: resource,
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('Google Sheets API response:', JSON.stringify(response, null, 2));
|
|
||||||
|
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
console.log('Data successfully appended to Google Sheet.');
|
console.log('Data successfully appended to Google Sheet.');
|
||||||
} else {
|
} else {
|
||||||
@@ -148,7 +136,6 @@ export async function writeDataToSheet(robotId: string, spreadsheetId: string, d
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export const processGoogleSheetUpdates = async () => {
|
export const processGoogleSheetUpdates = async () => {
|
||||||
while (true) {
|
while (true) {
|
||||||
let hasPendingTasks = false;
|
let hasPendingTasks = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user