Skip to content

Commit dc3d307

Browse files
Merge pull request #8 from modzy/v0.5routes_update
V0.5routes update
2 parents fa19e70 + 77140f5 commit dc3d307

File tree

5 files changed

+4738
-6634
lines changed

5 files changed

+4738
-6634
lines changed

src/job-client.js

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ class JobClient{
125125
.then(
126126
( response )=>{
127127
logger.info(`submitJob(${job.model.identifier}, ${job.model.version}) :: ${response.status} ${response.statusText}`);
128+
response.data.status = "SUBMITTED";
128129
return response.data;
129130
}
130131
)

src/model-client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ class ModelClient{
343343
* @return {String} A json string with the output sample
344344
* @throws {ApiError} Error if there is something wrong with the service or the call
345345
*/
346-
getModelVersionInputSample(modelId, versionId){
346+
getModelVersionOutputSample(modelId, versionId){
347347
const requestURL = `${this.baseURL}/${modelId}/versions/${versionId}/sample-output`;
348348
logger.debug(`getModelVersionOutputSample(${modelId}, ${versionId}) GET ${requestURL}`);
349349
return axios.get(

src/modzy-client.js

+25-21
Original file line numberDiff line numberDiff line change
@@ -283,27 +283,31 @@ class ModzyClient {
283283
*/
284284
blockUntilComplete(job) {
285285
logger.debug(`blockUntilComplete(${job.jobIdentifier}}) :: ${job.status}`);
286-
return this.jobClient.getJob(job.jobIdentifier)
287-
.then(
288-
(updatedJob) => {
289-
if (updatedJob.status === "SUBMITTED" || updatedJob.status === "IN_PROGRESS") {
290-
return new Promise(
291-
(resolve, reject) => {
292-
setTimeout(
293-
() => {
294-
resolve(
295-
this.blockUntilComplete(updatedJob)
296-
);
297-
},
298-
20000
299-
);
300-
}
301-
);
302-
}
303-
logger.debug(`blockUntilComplete(${updatedJob.jobIdentifier}}) :: returning :: ${updatedJob.status}`);
304-
return updatedJob;
305-
}
306-
)
286+
return new Promise(
287+
(resolve, reject) => {
288+
setTimeout(
289+
() => {
290+
this.jobClient.getJob(job.jobIdentifier)
291+
.then(
292+
(updatedJob) => {
293+
if (updatedJob.status === "SUBMITTED" || updatedJob.status === "IN_PROGRESS") {
294+
resolve(this.blockUntilComplete(updatedJob));
295+
}
296+
logger.debug(`blockUntilComplete(${updatedJob.jobIdentifier}}) :: returning :: ${updatedJob.status}`);
297+
resolve(updatedJob);
298+
}
299+
)
300+
.catch(
301+
(error) => {
302+
logger.error(error);
303+
reject(error);
304+
}
305+
);
306+
},
307+
2000
308+
);
309+
}
310+
);
307311
}
308312

309313
/**

tests/job-client.test.js

+20-3
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,26 @@ test(
115115
}
116116
)
117117
.then(
118-
(jobIdentifier)=>{
119-
logger.debug(`testCancelJob :: canceling job :: ${jobIdentifier}`);
120-
return jobClient.cancelJob(jobIdentifier);
118+
(jobIdentifier) => {
119+
return new Promise(
120+
(resolve, reject) => {
121+
setTimeout(
122+
() => {
123+
resolve(jobClient.getJob(jobIdentifier));
124+
},
125+
5000
126+
);
127+
}
128+
);
129+
}
130+
)
131+
.then(
132+
(job)=>{
133+
if( job.status != "COMPLETED" ){
134+
logger.debug(`testCancelJob :: canceling job :: ${job.jobIdentifier}`);
135+
return jobClient.cancelJob(job.jobIdentifier);
136+
}
137+
return job;
121138
}
122139
)
123140
.then(

0 commit comments

Comments
 (0)