Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.

Commit 2a1a196

Browse files
authored
Fix_Validation_issues (#523)
* Fix_Validation_issues * Update jobManager.ts * typo * Update jobHandler.ts * Update serverless.yml
1 parent 0546448 commit 2a1a196

File tree

12 files changed

+74
-67
lines changed

12 files changed

+74
-67
lines changed

.github/workflows/deploy-prd-ecs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ jobs:
5050
- name: Deploy Lambdas
5151
run: |
5252
npm ci
53-
sls deploy --stage dev
53+
sls deploy --stage prd

.github/workflows/deploy-stg-ecs.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,7 @@ jobs:
5353
sls deploy --stage stg
5454
aws ecs update-service --force-new-deployment --service docs-worker-pool-stg --cluster docs-worker-pool-stg
5555
56+
- name: Deploy Lambdas
57+
run: |
58+
npm ci
59+
sls deploy --stage stg

serverless.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
service: docs-worker-pool
1+
service: docs-worker-pool-api
22
variablesResolutionMode: 20210326
33

44
plugins:

src/job/jobHandler.ts

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { IRepoConnector } from "../services/repo";
77
import { IFileSystemServices } from "../services/fileServices";
88
import { AutoBuilderError, InvalidJobError, JobStoppedError, PublishError } from "../errors/errors";
99
import { IConfig } from "config";
10+
import { IJobValidator } from "./jobValidator";
1011
var fs = require('fs');
1112

1213
export abstract class JobHandler {
@@ -19,7 +20,7 @@ export abstract class JobHandler {
1920
protected get commandExecutor(): IJobCommandExecutor {
2021
return this._commandExecutor;
2122
}
22-
23+
2324
protected _cdnConnector: ICDNConnector;
2425

2526
private _repoConnector: IRepoConnector;
@@ -34,9 +35,9 @@ export abstract class JobHandler {
3435
return this._jobRepository;
3536
}
3637
private _fileSystemServices: IFileSystemServices;
37-
38+
3839
private _shouldStop: boolean;
39-
40+
4041
private _stopped: boolean;
4142
public get stopped(): boolean {
4243
return this._stopped;
@@ -45,12 +46,14 @@ export abstract class JobHandler {
4546
this._stopped = value;
4647
}
4748

49+
private _validator: IJobValidator;
50+
4851
protected _config: IConfig;
4952

50-
protected name:string;
53+
protected name: string;
5154

5255
constructor(job: IJob, config: IConfig, jobRepository: JobRepository, fileSystemServices: IFileSystemServices, commandExecutor: IJobCommandExecutor,
53-
cdnConnector: ICDNConnector, repoConnector: IRepoConnector, logger: IJobRepoLogger) {
56+
cdnConnector: ICDNConnector, repoConnector: IRepoConnector, logger: IJobRepoLogger, validator: IJobValidator) {
5457
this._commandExecutor = commandExecutor;
5558
this._cdnConnector = cdnConnector;
5659
this._repoConnector = repoConnector;
@@ -60,11 +63,12 @@ export abstract class JobHandler {
6063
this._fileSystemServices = fileSystemServices;
6164
this._shouldStop = false;
6265
this._config = config;
66+
this._validator = validator;
6367
}
6468

6569
abstract prepStageSpecificNextGenCommands(): void;
6670

67-
private async update(publishResult:CommandExecutorResponse): Promise<void> {
71+
private async update(publishResult: CommandExecutorResponse): Promise<void> {
6872
if (publishResult && publishResult.status === 'success') {
6973
let files = this._fileSystemServices.getFilesInDirectory(`./${this.currJob.payload.repoName}/build/public`, '', null, null);
7074
await this.jobRepository.updateWithCompletionStatus(this.currJob._id, files);
@@ -92,7 +96,7 @@ export abstract class JobHandler {
9296
@throwIfJobInterupted()
9397
private async logError(error): Promise<void> {
9498
await this._logger.save(this.currJob._id, `${'(BUILD)'.padEnd(15)}failed with code: ${error.code}. `);
95-
await this._logger.save(this.currJob._id, `${'(BUILD)'.padEnd(15)}stdErr: ${error.stderr}`);
99+
await this._logger.save(this.currJob._id, `${'(BUILD)'.padEnd(15)}stdErr: ${error.stderr}`);
96100
}
97101

98102
@throwIfJobInterupted()
@@ -164,13 +168,17 @@ export abstract class JobHandler {
164168
@throwIfJobInterupted()
165169
private async prepNextGenBuild(): Promise<void> {
166170
if (this.isbuildNextGen()) {
171+
await this._validator.throwIfBranchNotConfigured(this.currJob);
167172
await this.constructPrefix();
168173
if (!this.currJob.payload.aliased || (this.currJob.payload.aliased && this.currJob.payload.primaryAlias)) {
169174
await this.constructManifestIndexPath();
170175
}
171176
this.prepStageSpecificNextGenCommands();
172177
this.constructEnvVars();
173178
this.currJob.payload.isNextGen = true;
179+
if (this._currJob.payload.jobType === 'productionDeploy') {
180+
this._validator.throwIfItIsNotPublishable(this._currJob);
181+
}
174182
} else {
175183
this.currJob.payload.isNextGen = false;
176184
}
@@ -187,35 +195,35 @@ export abstract class JobHandler {
187195
if (resp.status != 'success') {
188196
const error = new AutoBuilderError(resp.error, "BuildError")
189197
await this.logError(error);
190-
throw error
198+
throw error
191199
}
192200
} else {
193201
const error = new AutoBuilderError("No commands to execute", "BuildError")
194202
await this.logError(error);
195-
throw error
203+
throw error
196204
}
197205
return true;
198206
}
199207

200208
private constructEnvVars(): void {
201-
let envVars = `GATSBY_PARSER_USER=${ this._config.get<string>("GATSBY_PARSER_USER")}\nGATSBY_PARSER_BRANCH=${this.currJob.payload.branchName}\n`;
209+
let envVars = `GATSBY_PARSER_USER=${this._config.get<string>("GATSBY_PARSER_USER")}\nGATSBY_PARSER_BRANCH=${this.currJob.payload.branchName}\n`;
202210
const pathPrefix = this.currJob.payload.pathPrefix;
203-
if(typeof pathPrefix !== 'undefined' && pathPrefix !== null){
204-
envVars += `PATH_PREFIX=${pathPrefix}\n`
211+
if (typeof pathPrefix !== 'undefined' && pathPrefix !== null) {
212+
envVars += `PATH_PREFIX=${pathPrefix}\n`
205213
}
206214
// const snootyFrontEndVars = {
207215
// 'GATSBY_FEATURE_FLAG_CONSISTENT_NAVIGATION': this._config.get<boolean>("gatsbyConsitentNavFlag"),
208216
// 'GATSBY_FEATURE_FLAG_SDK_VERSION_DROPDOWN': this._config.get<boolean>("gatsbySDKVersionDropdownFlag"),
209217

210218
// };
211-
219+
212220
// for (const[envName, envValue] of Object.entries(snootyFrontEndVars)) {
213221
// if (envValue) envVars += `${envName}=TRUE\n`;
214222
// }
215-
this._fileSystemServices.writeToFile(`repos/${this.currJob.payload.repoName}/.env.production`, envVars, { encoding: 'utf8', flag: 'w' });
223+
this._fileSystemServices.writeToFile(`repos/${this.currJob.payload.repoName}/.env.production`, envVars, { encoding: 'utf8', flag: 'w' });
216224
}
217225

218-
protected getPathPrefix(): Promise<string|undefined> {
226+
protected getPathPrefix(): Promise<string | undefined> {
219227
return Promise.resolve(undefined);
220228
}
221229

@@ -230,45 +238,46 @@ export abstract class JobHandler {
230238
protected prepBuildCommands(): void {
231239
this.currJob.buildCommands = [
232240
`. /venv/bin/activate`,
233-
`cd repos/${ this.currJob.payload.repoName}`,
241+
`cd repos/${this.currJob.payload.repoName}`,
234242
`rm -f makefile`,
235243
`make html`
236244
];
237245
}
238246

239247
@throwIfJobInterupted()
240248
protected async build(): Promise<boolean> {
241-
this.cleanup();
242-
await this.cloneRepo(this._config.get<string>("repo_dir"));
243-
this._logger.info(this._currJob._id,"Cloned Repo");
244-
await this.commitCheck();
245-
this._logger.info(this._currJob._id,"Checked Commit");
246-
await this.pullRepo();
247-
this._logger.info(this._currJob._id,"Pulled Repo");
248-
await this._repoConnector.applyPatch(this.currJob);
249-
this._logger.info(this._currJob._id,"Patch Applied");
250-
await this.downloadMakeFile();
251-
this._logger.info(this._currJob._id,"Downloaded Makefile");
252-
this.prepBuildCommands();
253-
this._logger.info(this._currJob._id,"Prepared Build commands");
254-
await this.prepNextGenBuild();
255-
this._logger.info(this._currJob._id,"Prepared Next Gen build");
256-
return await this.executeBuild();
249+
this.cleanup();
250+
await this.cloneRepo(this._config.get<string>("repo_dir"));
251+
this._logger.info(this._currJob._id, "Cloned Repo");
252+
await this.commitCheck();
253+
this._logger.info(this._currJob._id, "Checked Commit");
254+
await this.pullRepo();
255+
this.prepBuildCommands();
256+
this._logger.info(this._currJob._id, "Prepared Build commands");
257+
await this.prepNextGenBuild();
258+
this._logger.info(this._currJob._id, "Pulled Repo");
259+
await this._repoConnector.applyPatch(this.currJob);
260+
this._logger.info(this._currJob._id, "Patch Applied");
261+
await this.downloadMakeFile();
262+
this._logger.info(this._currJob._id, "Downloaded Makefile");
263+
264+
this._logger.info(this._currJob._id, "Prepared Next Gen build");
265+
return await this.executeBuild();
257266
}
258267

259268
@throwIfJobInterupted()
260269
protected async deployGeneric(): Promise<CommandExecutorResponse> {
261270
this.prepDeployCommands();
262271
await this._logger.save(this.currJob._id, `${this._config.get<string>('stage').padEnd(15)}Pushing to ${this.name}`);
263-
264-
if (this.currJob.deployCommands && this.currJob.deployCommands.length > 0 ) {
272+
273+
if (this.currJob.deployCommands && this.currJob.deployCommands.length > 0) {
265274
const resp = await this._commandExecutor.execute(this.currJob.deployCommands)
266-
if (resp && resp.error && typeof(resp.error) === 'string' && resp.error.indexOf('ERROR') !== -1) {
275+
if (resp && resp.error && typeof (resp.error) === 'string' && resp.error.indexOf('ERROR') !== -1) {
267276
await this._logger.save(this.currJob._id, `${this._config.get<string>('stage').padEnd(15)}Failed to push to ${this.name}`);
268277
throw new PublishError(`Failed pushing to ${this.name}: ${resp.error}`)
269-
}
270-
await this._logger.save(this.currJob._id,`${this._config.get<string>('stage').padEnd(15)}Finished pushing to ${this.name}`);
271-
await this._logger.save(this.currJob._id,`${this._config.get<string>('stage').padEnd(15)}Staging push details:\n\n${resp.output}`);
278+
}
279+
await this._logger.save(this.currJob._id, `${this._config.get<string>('stage').padEnd(15)}Finished pushing to ${this.name}`);
280+
await this._logger.save(this.currJob._id, `${this._config.get<string>('stage').padEnd(15)}Staging push details:\n\n${resp.output}`);
272281
return resp;
273282

274283
} else {

src/job/jobManager.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@ import { IFileSystemServices } from "../services/fileServices";
1515
import { IConfig } from "config";
1616

1717
export class JobHandlerFactory {
18-
public createJobHandler(job: IJob, config: IConfig, jobRepository:JobRepository, fileSystemServices:IFileSystemServices, commandExecutor: IJobCommandExecutor, cdnConnector:ICDNConnector, repoConnector:IRepoConnector, logger: IJobRepoLogger) : JobHandler {
18+
public createJobHandler(job: IJob, config: IConfig, jobRepository:JobRepository, fileSystemServices:IFileSystemServices,
19+
commandExecutor: IJobCommandExecutor, cdnConnector:ICDNConnector, repoConnector:IRepoConnector, logger: IJobRepoLogger, validator: IJobValidator) : JobHandler {
1920
if (job.payload.jobType === "regression") {
20-
return new RegressionJobHandler(job, config, jobRepository, fileSystemServices, commandExecutor, cdnConnector, repoConnector, logger);
21+
return new RegressionJobHandler(job, config, jobRepository, fileSystemServices, commandExecutor, cdnConnector, repoConnector, logger,validator);
2122
} else if (job.payload.jobType === "githubPush") {
22-
return new StagingJobHandler(job, config, jobRepository, fileSystemServices, commandExecutor, cdnConnector, repoConnector, logger);
23+
return new StagingJobHandler(job, config, jobRepository, fileSystemServices, commandExecutor, cdnConnector, repoConnector, logger,validator);
2324
} else if (job.payload.jobType === "productionDeploy") {
24-
return new ProductionJobHandler(job, config, jobRepository, fileSystemServices, commandExecutor, cdnConnector, repoConnector, logger);
25+
return new ProductionJobHandler(job, config, jobRepository, fileSystemServices, commandExecutor, cdnConnector, repoConnector, logger,validator);
2526
} else if (job.payload.jobType === "publishDochub") {
26-
return new ProductionJobHandler(job, config, jobRepository, fileSystemServices, commandExecutor, cdnConnector, repoConnector, logger);
27+
return new ProductionJobHandler(job, config, jobRepository, fileSystemServices, commandExecutor, cdnConnector, repoConnector, logger,validator);
2728
}
2829
throw new InvalidJobError("Job type not supported");
2930
}
@@ -99,13 +100,8 @@ export class JobManager {
99100

100101
async createHandlerAndExecute(job: IJob): Promise<void> {
101102
this._jobHandler = this._jobHandlerFactory.createJobHandler(job, this._config, this._jobRepository,
102-
this._fileSystemServices, this._jobCommandExecutor, this._cdnConnector, this._repoConnector, this._logger);
103+
this._fileSystemServices, this._jobCommandExecutor, this._cdnConnector, this._repoConnector, this._logger, this._jobValidator);
103104

104-
if ( this._jobHandler.isbuildNextGen()) {
105-
job.payload.isNextGen = true
106-
} else {
107-
job.payload.isNextGen = false
108-
}
109105
await this._jobValidator.throwIfJobInvalid(job);
110106
await this._jobHandler?.execute();
111107
await this._logger.save(job._id, `${' (DONE)'.padEnd(this._config.get("LOG_PADDING"))}Finished Job with ID: ${job._id}`);

src/job/jobValidator.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,6 @@ export class JobValidator implements IJobValidator {
5151
if (this.isProd(job.payload.jobType)) {
5252
await this.throwIfUserNotEntitled(job);
5353
}
54-
if (job.payload.isNextGen) {
55-
await this.throwIfBranchNotConfigured(job);
56-
}
57-
if (this.isProd(job.payload.jobType)) {
58-
this.throwIfItIsNotPublishable(job);
59-
}
60-
6154
}
6255

6356
private isProd(jobType: string): boolean {

src/job/productionJobHandler.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ import { IFileSystemServices } from "../services/fileServices";
99
import { IJobRepoLogger } from "../services/logger";
1010
import { IRepoConnector } from "../services/repo";
1111
import { JobHandler } from "./jobHandler";
12+
import { IJobValidator } from "./jobValidator";
1213

1314
export class ProductionJobHandler extends JobHandler {
1415

1516
constructor(job: IJob, config: IConfig, jobRepository: JobRepository, fileSystemServices: IFileSystemServices, commandExecutor: IJobCommandExecutor,
16-
cdnConnector: ICDNConnector, repoConnector: IRepoConnector, logger: IJobRepoLogger) {
17-
super(job, config, jobRepository, fileSystemServices, commandExecutor, cdnConnector, repoConnector, logger);
17+
cdnConnector: ICDNConnector, repoConnector: IRepoConnector, logger: IJobRepoLogger, validator:IJobValidator) {
18+
super(job, config, jobRepository, fileSystemServices, commandExecutor, cdnConnector, repoConnector, logger, validator);
1819
this.name = "Production";
1920
}
2021
prepDeployCommands(): void {

src/job/regressionJobHandler.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ import { IJobCommandExecutor } from "../services/commandExecutor";
66
import { IFileSystemServices } from "../services/fileServices";
77
import { IJobRepoLogger } from "../services/logger";
88
import { IRepoConnector } from "../services/repo";
9+
import { IJobValidator } from "./jobValidator";
910
import { ProductionJobHandler } from "./productionJobHandler";
1011

1112
export class RegressionJobHandler extends ProductionJobHandler {
1213

1314
constructor(job: IJob, config: IConfig, jobRepository: JobRepository, fileSystemServices: IFileSystemServices, commandExecutor: IJobCommandExecutor,
14-
cdnConnector: ICDNConnector, repoConnector: IRepoConnector, logger: IJobRepoLogger) {
15-
super(job, config, jobRepository, fileSystemServices, commandExecutor, cdnConnector, repoConnector, logger);
15+
cdnConnector: ICDNConnector, repoConnector: IRepoConnector, logger: IJobRepoLogger, validator:IJobValidator) {
16+
super(job, config, jobRepository, fileSystemServices, commandExecutor, cdnConnector, repoConnector, logger,validator);
1617
this.name = "Regression";
1718
}
1819
}

src/job/stagingJobHandler.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import { CommandExecutorResponse, IJobCommandExecutor } from "../services/comman
77
import { IFileSystemServices } from "../services/fileServices";
88
import { IJobRepoLogger } from "../services/logger";
99
import { IRepoConnector } from "../services/repo";
10+
import { IJobValidator } from "./jobValidator";
1011

1112
export class StagingJobHandler extends JobHandler {
1213
constructor(job: IJob, config: IConfig, jobRepository: JobRepository, fileSystemServices: IFileSystemServices, commandExecutor: IJobCommandExecutor,
13-
cdnConnector: ICDNConnector, repoConnector: IRepoConnector, logger: IJobRepoLogger) {
14-
super(job, config, jobRepository, fileSystemServices, commandExecutor, cdnConnector, repoConnector, logger);
14+
cdnConnector: ICDNConnector, repoConnector: IRepoConnector, logger: IJobRepoLogger, validator:IJobValidator) {
15+
super(job, config, jobRepository, fileSystemServices, commandExecutor, cdnConnector, repoConnector, logger, validator);
1516
this.name = "Staging";
1617
}
1718

tests/unit/job/jobValidator.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ describe('JobValidator Tests', () => {
9797
job.payload.isNextGen=true;
9898
fileSystemServices.downloadYaml.calledWith(`https://raw.githubusercontent.com/mongodb/docs-worker-pool/meta/publishedbranches/${job.payload.repoName}.yaml`).mockReturnValue( { status: 'success', content:pubBranchRetVal});
9999
await jobValidator.throwIfJobInvalid(job);
100-
expect(fileSystemServices.downloadYaml).toHaveBeenCalledTimes(1);
101100
expect(repoEntitlementRepository.getRepoEntitlementsByGithubUsername).toHaveBeenCalledTimes(0);
102101

103102
})

0 commit comments

Comments
 (0)