Skip to content

Commit

Permalink
style(infra service): use env var rather than inline const
Browse files Browse the repository at this point in the history
  • Loading branch information
kishore03109 committed May 22, 2023
1 parent b109eed commit faed0d0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ const config = convict({
format: "required-string",
default: "",
},
areQueuesDeprecated: {
doc: "Whether the queues are deprecated",
env: "ARE_QUEUES_DEPRECATED",
format: "required-boolean",
default: false,
},
},
},
github: {
Expand Down
2 changes: 1 addition & 1 deletion src/services/infra/DynamoDBService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default class DynamoDBService {
await this.dynamoDBClient.createItem(this.TABLE_NAME, message)
}

async getAllSuccessOrFailureLaunches(): Promise<SiteLaunchMessage[]> {
async getAllCompletedLaunches(): Promise<SiteLaunchMessage[]> {
const entries = ((await this.dynamoDBClient.getAllItems(this.TABLE_NAME))
.Items as unknown) as SiteLaunchMessage[]

Expand Down
8 changes: 4 additions & 4 deletions src/services/infra/InfraService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type CreateSiteParams = {
isEmailLogin: boolean
}

const ARE_QUEUES_DEPRECIATED = false
const ARE_QUEUES_DEPRECATED = config.get("aws.sqs.areQueuesDeprecated")
export default class InfraService {
private readonly sitesService: InfraServiceProps["sitesService"]

Expand Down Expand Up @@ -384,7 +384,7 @@ export default class InfraService {
message.redirectionDomain = [redirectionDomainObject]
}

if (ARE_QUEUES_DEPRECIATED) {
if (ARE_QUEUES_DEPRECATED) {
this.dynamoDBService.createItem(message)
this.stepFunctionsService.triggerFlow(message)
} else {
Expand All @@ -402,8 +402,8 @@ export default class InfraService {
}

siteUpdate = async () => {
const messages = ARE_QUEUES_DEPRECIATED
? await this.dynamoDBService.getAllSuccessOrFailureLaunches()
const messages = ARE_QUEUES_DEPRECATED
? await this.dynamoDBService.getAllCompletedLaunches()
: await this.queueService.pollMessages()
await Promise.all(
messages.map(async (message) => {
Expand Down
2 changes: 1 addition & 1 deletion src/services/infra/__tests__/DynamoDBService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe("DynamoDBService", () => {
Items: [mockSuccessLaunch, mockLaunch, mockFailureLaunch],
}
mockDynamoDBClient.getAllItems.mockReturnValueOnce(scanCommandOutput)
const result: SiteLaunchMessage[] = await dynamoDBService.getAllSuccessOrFailureLaunches()
const result: SiteLaunchMessage[] = await dynamoDBService.getAllCompletedLaunches()
expect(dynamoDBClient.getAllItems).toHaveBeenCalledWith(tableName)
expect(spyDynamoDBService.deleteItem).toHaveBeenCalledWith(
mockSuccessLaunch
Expand Down

0 comments on commit faed0d0

Please sign in to comment.