From 6b98bbce7c0d187ccf4f9b2bbb08c4da8e96b5a8 Mon Sep 17 00:00:00 2001 From: Krishna Acondy Date: Tue, 1 Sep 2020 11:12:56 +0100 Subject: [PATCH 1/3] chore(types): add code property to Job model --- src/types/Job.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/types/Job.ts b/src/types/Job.ts index ccd8314..cee59d6 100644 --- a/src/types/Job.ts +++ b/src/types/Job.ts @@ -6,6 +6,7 @@ export interface Job { name: string; uri: string; createdBy: string; + code?: string; links: Link[]; results: JobResult; error?: any; From 83fb89f77975f642bf5a56bd58ea963f155b7b47 Mon Sep 17 00:00:00 2001 From: Krishna Acondy Date: Tue, 1 Sep 2020 11:13:52 +0100 Subject: [PATCH 2/3] fix(*): cache job definition code after first fetch, make initial state request before poll --- src/SASViyaApiClient.ts | 53 +++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/src/SASViyaApiClient.ts b/src/SASViyaApiClient.ts index d8f5e0e..60301a6 100644 --- a/src/SASViyaApiClient.ts +++ b/src/SASViyaApiClient.ts @@ -675,20 +675,30 @@ export class SASViyaApiClient { const jobName = sasJob.split("/")[1]; const jobFolder = this.rootFolderMap.get(folderName); const jobToExecute = jobFolder?.find((item) => item.name === jobName); - const jobDefinitionLink = jobToExecute?.links.find( - (l) => l.rel === "getResource" - ); - if (!jobDefinitionLink) { - console.error("Job definition URI was not found."); - throw new Error("Job definition URI was not found."); + if (!jobToExecute) { + throw new Error("Job was not found."); } - const { result: jobDefinition } = await this.request( - `${this.serverUrl}${jobDefinitionLink.href}`, - headers - ); - const linesToExecute = jobDefinition.code - .replace(/\r\n/g, "\n") - .split("\n"); + + let code = jobToExecute?.code; + if (!code) { + const jobDefinitionLink = jobToExecute?.links.find( + (l) => l.rel === "getResource" + ); + if (!jobDefinitionLink) { + console.error("Job definition URI was not found."); + throw new Error("Job definition URI was not found."); + } + const { result: jobDefinition } = await this.request( + `${this.serverUrl}${jobDefinitionLink.href}`, + headers + ); + + code = jobDefinition.code; + + // Add code to existing job definition + jobToExecute.code = code; + } + const linesToExecute = code.replace(/\r\n/g, "\n").split("\n"); return await this.executeScript( sasJob, linesToExecute, @@ -928,6 +938,23 @@ export class SASViyaApiClient { headers.Authorization = `Bearer ${accessToken}`; } const stateLink = postedJob.links.find((l: any) => l.rel === "state"); + if (!stateLink) { + Promise.reject("Job state link was not found."); + } + + const { result: state } = await this.request( + `${this.serverUrl}${stateLink.href}?_action=wait&wait=30`, + { + headers + }, + "text" + ); + + const currentState = state.trim(); + if (currentState === "completed") { + return Promise.resolve(currentState); + } + return new Promise(async (resolve, _) => { const interval = setInterval(async () => { if ( From a587d9f6de478b090a83a081ce92287a8ddbe5ec Mon Sep 17 00:00:00 2001 From: Krishna Acondy Date: Tue, 1 Sep 2020 11:20:46 +0100 Subject: [PATCH 3/3] chore(ci): add lint action --- .github/workflows/build.yml | 8 ++++++-- .github/workflows/npmpublish.yml | 2 ++ package.json | 3 +-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c8cbd70..1c14f1e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,7 +21,11 @@ jobs: uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} - - run: npm ci - - run: npm run package:lib + - name: Install Dependencies + run: npm ci + - name: Check code style + run: npm run lint + - name: Build Package + run: npm run package:lib env: CI: true diff --git a/.github/workflows/npmpublish.yml b/.github/workflows/npmpublish.yml index 687fc5a..bd7ce8b 100644 --- a/.github/workflows/npmpublish.yml +++ b/.github/workflows/npmpublish.yml @@ -16,6 +16,8 @@ jobs: uses: actions/checkout@v2 - name: Install Dependencies run: npm ci + - name: Check code style + run: npm run lint - name: Build Project run: npm run build - name: Semantic Release diff --git a/package.json b/package.json index d7a7cb7..20d1989 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "package:lib": "npm run build && cp ./package.json build && cd build && npm version \"5.0.0\" && npm pack", "publish:lib": "npm run build && cd build && npm publish", "lint:fix": "npx prettier --write 'src/**/*.{ts,tsx,js,jsx,html,css,sass,less,json,yml,md,graphql}'", - "lint": "tslint -p tsconfig.json", + "lint": "npx prettier --check 'src/**/*.{ts,tsx,js,jsx,html,css,sass,less,json,yml,md,graphql}'", "test": "jest", "prepublishOnly": "cp -r ./build/* . && rm -rf ./build", "postpublish": "git clean -fd", @@ -41,7 +41,6 @@ "cp": "^0.2.0", "jest": "^25.5.4", "path": "^0.12.7", - "prettier": "^2.1.1", "rimraf": "^3.0.2", "semantic-release": "^17.1.1", "ts-jest": "^25.5.1",