Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/course/student-projects/run-in-all-projects.ts
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import {6start_project,7exec,8} from "@cocalc/frontend/frame-editors/generic/client";9import { map as awaitMap } from "awaiting";10import { MAX_PARALLEL_TASKS } from "./actions";1112async function run_in_project(13project_id: string,14command: string,15args?: string[],16timeout?: number,17): Promise<any> {18await start_project(project_id, 60);19return await exec({ project_id, command, args, timeout, err_on_exit: false });20}2122export type Result = {23project_id: string;24stdout: string;25stderr: string;26exit_code: number;27timeout?: number;28total_time: number;29};3031export async function run_in_all_projects(32project_ids: string[],33command: string,34args?: string[],35timeout?: number,36log?: Function,37): Promise<Result[]> {38let start = Date.now();39const task = async (project_id) => {40let result: Result;41try {42result = {43...(await run_in_project(project_id, command, args, timeout)),44project_id,45timeout,46total_time: (Date.now() - start) / 1000,47};48} catch (err) {49result = {50project_id,51stdout: "",52stderr: err.toString(),53exit_code: -1,54total_time: (Date.now() - start) / 1000,55timeout,56};57}58if (log != null) {59log(result);60}61return result;62};6364return await awaitMap(project_ids, MAX_PARALLEL_TASKS, task);65}666768