Skip to content

Commit 023b620

Browse files
Japneet Singh ChawlaJapneet Singh Chawla
authored andcommitted
command for session stop added
1 parent e2a54ca commit 023b620

File tree

2 files changed

+49
-18
lines changed

2 files changed

+49
-18
lines changed

commands/build_stop.js

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const request = require("request");
22
const constants = require("./utils/constants.js");
33
const process = require("process");
4-
5-
function stop_build(args) {
4+
const fs = require("fs");
5+
function stop_session(args) {
66
return new Promise(function (resolve, reject) {
77
var username = "";
88
var access_key = "";
@@ -25,13 +25,34 @@ function stop_build(args) {
2525
} else {
2626
reject("Access Key not provided");
2727
}
28-
29-
if (
30-
!("buildId" in args) ||
31-
args["buildid"] == "" ||
32-
args["buildid"] == undefined
33-
) {
34-
reject("Please provide a build ID");
28+
if ("stop_last_session" in args) {
29+
const file_path = "lambdatest_run.json";
30+
if (fs.existsSync(file_path)) {
31+
let lambda_run = fs.readFileSync(file_path);
32+
try {
33+
let lambda_run_obj = JSON.parse(lambda_run);
34+
if (!("session_id" in lambda_run_obj)) {
35+
throw new Error("session_id is missing from the file");
36+
}
37+
args.session_id = lambda_run_obj.session_id;
38+
} catch (e) {
39+
reject(
40+
"Error!! lambdatest_run.json file is tempered Err: " + e.message
41+
);
42+
}
43+
} else {
44+
reject(
45+
"Error!! Last session details not found, lambdatest_run.json file not present!!"
46+
);
47+
}
48+
} else {
49+
if (
50+
!("session_id" in args) ||
51+
args["session_id"] == "" ||
52+
args["session_id"] == undefined
53+
) {
54+
reject("Error!! Please provide a Session ID");
55+
}
3556
}
3657
var env = "prod";
3758
if ("env" in args) {
@@ -45,7 +66,7 @@ function stop_build(args) {
4566
}
4667

4768
let options = {
48-
url: constants[env].BUILD_STOP_URL + args.buildId,
69+
url: constants[env].BUILD_STOP_URL + args.session_id,
4970
headers: {
5071
Authorization: "Token " + access_key,
5172
Username: username,
@@ -69,15 +90,21 @@ function stop_build(args) {
6990
reject("error", responseData);
7091
}
7192
} else {
72-
resolve("Build Stopped successfully");
93+
if (responseData.length == 0) {
94+
resolve("No tests to stop in session " + args.session_id);
95+
}
96+
resolve(
97+
"Session Stopped successfully, No. of tests stopped are: " +
98+
responseData.length
99+
);
73100
}
74101
}
75102
});
76103
});
77104
}
78105

79106
module.exports = function (args) {
80-
stop_build(args)
107+
stop_session(args)
81108
.then(function (resp) {
82109
console.log(resp);
83110
})

index.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,25 +159,29 @@ const argv = require("yargs")
159159
function (yargs) {
160160
return yargs
161161
.option("id", {
162-
alias: "build-id",
163-
describe: "Build Identifier",
162+
alias: "session_id",
163+
describe: "Session Identifier",
164164
type: "string",
165-
demandOption: true,
166165
})
167166
.option("user", {
168-
alias: "user",
167+
alias: "username",
169168
describe: "username",
170169
type: "string",
171170
})
172-
.option("access_key", {
171+
.option("ak", {
173172
alias: "access_key",
174173
describe: "Access Key",
175174
type: "string",
176175
})
177176
.option("env", {
178-
alias: "env",
177+
alias: "environment",
179178
describe: "environment",
180179
type: "string",
180+
})
181+
.option("sls", {
182+
alias: "stop_last_session",
183+
describe: "stop last session",
184+
type: "bool",
181185
});
182186
},
183187
function (argv) {

0 commit comments

Comments
 (0)