import chalk from 'chalk'; import { getTaskDataSummary, pullTask } from '../../apis/taskAPI'; import { readVariableValue } from '../../helpers/variablesHelper'; import { appendAPIEventLog, beginLog, beginSessionLog, endLog, } from '../../helpers/logObj'; import { formatDuration, getFormattedDate } from '../../helpers/datetime'; import { errorSymbol } from '../../helpers/log'; import { findEntitiesByIdOrName } from '../../helpers/entityHelper'; export async function pullTaskByIdOrName( taskId: string, taskName: string, profileId: string, workerUrl: string, ) { const searchedTasks = await findEntitiesByIdOrName(taskId, taskName, 'task'); if (!searchedTasks?.length) { console.log( `${errorSymbol()} No tasks found for ${chalk.red(taskId || taskName)}`, ); return; } const event = `test-pull-task-${getFormattedDate()}`; beginLog(event); try { for (var task of searchedTasks) { var title = `${readVariableValue(task.entityName!)} (${readVariableValue(task.entityId)})`; // try { beginSessionLog(event, title); const start = Date.now(); var pullResponse = await pullTask(task, profileId, workerUrl); const end = Date.now(); appendAPIEventLog(event, pullResponse, task, start, end); if (!pullResponse?.success) { continue; } // var taskDataSummaryResponse = await getTaskDataSummary(task, profileId, workerUrl); // appendAPIEventLog(event, taskDataSummaryResponse, task); var duration = end - start; if (duration > 60000) { console.log( `${errorSymbol()} Task ${chalk.red(title)} took ${chalk.red(formatDuration(duration))} to pull`, ); } else { console.log( `${chalk.green('✓')} Task ${chalk.green(title)} pulled in ${chalk.green(formatDuration(duration))}`, ); } // } finally { // endSessionLog(event) // } } } finally { endLog(event); } }