UNPKG

@pradyumn-el/pollycli

Version:

pollycli lets users access the functionalities of Polly over a command line interface

74 lines (62 loc) 2.36 kB
const axios = require("axios"); const chalk = require("chalk"); const pollyEnv = require('./env.json'); const pollymsg = require('./message'); const getWorkflowClient = () => { const auth_token = pollystore.get(`${pollystore.get('pollyUser').pollyemail}`).pollyrefreshToken; const workflowClient = axios.create({ baseURL: `${pollyEnv.computeApi}/workflow`, headers: {'Authorization': `Bearer ${auth_token}`} }); return workflowClient; } export const submitWorkflow = async (workspace_id, config) => { try { const workflowClient = getWorkflowClient(); let { pipeline, main_script, container } = config; if(!pipeline.endsWith("/")) { pipeline = pipeline + "/"; } const body = { workspace_id, pipeline, } if(!!container) { body.container = container; } if(!!main_script) { body.main_script = main_script } const res = await workflowClient.post("/", body); pollymsg.pollySuccess(`${res.data.message}, run_id = ${res.data.id}`); console.log(chalk.bold(`status: polly workflows status --run-id=${res.data.id}`)); console.log(chalk.bold(`logs : polly workflows logs --run-id=${res.data.id}`)); console.log(chalk.bold(`cancel: polly workflows cancel --run-id=${res.data.id}`)); } catch(e) { console.log(e); } } export const deleteWorkflow = async (run_id) => { const workflowClient = getWorkflowClient(); const res = await workflowClient.delete(`/${run_id}`); pollymsg.pollySuccess("workflow execution terminated"); } export const getWorkflow = async (run_id) => { const workflowClient = getWorkflowClient(); const res = await workflowClient.get(`/${run_id}`); if(res.data.status === "failed") { console.log(chalk.bold.red(`workflow ${res.data.status}`)); } else { console.log(chalk.bold.green(`workflow ${res.data.status}`)) } } export const getWorkflowLogs = async (run_id) => { const workflowClient = getWorkflowClient(); const res = await workflowClient.get(`/${run_id}/logs`); if(res.data.logs.length === 0) { console.log('logs not yet generated'); return; } console.log(chalk.bold.italic("logs:")); console.log(res.data.logs); }