Skip to content

Commit

Permalink
udpate:start and stop user application
Browse files Browse the repository at this point in the history
  • Loading branch information
shivamsouravjha committed Nov 4, 2023
1 parent 8771fa1 commit bb48183
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
19 changes: 15 additions & 4 deletions keployV2/keployCli.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import axios from 'axios';
import { exec, execSync, spawn, ChildProcess } from 'child_process';
const treeKill = require('tree-kill');

const GRAPHQL_ENDPOINT = '/query';
const HOST = 'http://localhost:';
Expand All @@ -18,6 +19,19 @@ export const setTestRunCompletionStatus = (status: boolean) => {
hasTestRunCompleted = status;
};

let userCommandPID:any = 0;

export const StartUserApplication = (userCmd:string) =>{
const [cmd, ...args] = userCmd.split(' ');
const npmStartProcess = spawn(cmd, args,{
stdio: [process.stdin, 'pipe', process.stderr],
});
userCommandPID = npmStartProcess.pid
}

export const StopUserApplication = () =>{
treeKill(userCommandPID)
}
let childProcesses: ChildProcess[] = [];
const processWrap = (command: string): Promise<void> => {
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -182,7 +196,6 @@ export const FetchTestSets = async (): Promise<string[] | null> => {
return null;
};


export const FetchTestSetStatus = async (testRunId: string): Promise<TestRunStatus | null> => {
try {
const client = await setHttpClient();
Expand Down Expand Up @@ -211,10 +224,8 @@ export const RunTestSet = async (testSetName: string): Promise<string | null> =>
if (!client) throw new Error("Could not initialize HTTP client.");

const response = await client.post('', {
timeout: 5000, // Set a timeout (5000 ms or 5 seconds, adjust as necessary)
query: `mutation { runTestSet(testSet: "${testSetName}") { success testRunId message } }`
});

if (response.data && response.data.data && response.data.data.runTestSet) {
return response.data.data.runTestSet.testRunId;
} else {
Expand All @@ -226,10 +237,10 @@ export const RunTestSet = async (testSetName: string): Promise<string | null> =>
return null;
};


export const StopKeployServer = () => {
return killProcessOnPort(serverPort);
};

export const killProcessOnPort = async (port: number): Promise<void> => {
return new Promise<void>((resolve, reject) => {
//console.debug(`Trying to kill process running on port: ${port}`);
Expand Down
17 changes: 12 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"import-in-the-middle": "^1.3.4",
"merge-descriptors": "^1.0.1",
"node-fetch": "^2.6.7",
"require-in-the-middle": "^5.1.0"
"require-in-the-middle": "^5.1.0",
"tree-kill": "^1.2.2"
},
"description": "[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen?logo=github)](CODE_OF_CONDUCT.md) [![Slack](.github/slack.svg)](https://join.slack.com/t/keploy/shared_invite/zt-12rfbvc01-o54cOG0X1G6eVJTuI_orSA) [![License](.github/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)",
"bugs": {
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3462,6 +3462,11 @@ tr46@~0.0.3:
resolved "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz"
integrity sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==

tree-kill@^1.2.2:
version "1.2.2"
resolved "https://registry.npmjs.org/tree-kill/-/tree-kill-1.2.2.tgz"
integrity sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==

trim-newlines@^3.0.0:
version "3.0.1"
resolved "https://registry.npmjs.org/trim-newlines/-/trim-newlines-3.0.1.tgz"
Expand Down

0 comments on commit bb48183

Please sign in to comment.