-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: cleanup idle stages by project tag (#35)
- Loading branch information
Showing
7 changed files
with
110 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { ListStagesCommand } from '@aws-sdk/client-ivs-realtime'; | ||
|
||
import { | ||
ivsRealTimeClient, | ||
getIdleStageArns, | ||
deleteStagesWithRetry, | ||
updateMultipleChannelDynamoItems, | ||
getBatchChannelWriteUpdates, | ||
getIdleStages | ||
} from './helpers'; | ||
|
||
export const handler = async () => { | ||
try { | ||
const deleteIdleStages = async (nextToken = '') => { | ||
const listStagesCommand = new ListStagesCommand({ | ||
maxResults: 100, | ||
nextToken | ||
}); | ||
const response = await ivsRealTimeClient.send(listStagesCommand); | ||
|
||
const stages = response?.stages || []; | ||
const _nextToken = response?.nextToken || ''; | ||
|
||
if (stages.length) { | ||
// Filter list of stages by stack name | ||
const projectStages = stages.filter( | ||
({ tags }) => !!tags?.stack && tags.stack === process.env.STACK_TAG | ||
); | ||
const idleStages = getIdleStages(projectStages); | ||
const idleStageArns = getIdleStageArns(idleStages); | ||
const batchChannelWriteUpdates = | ||
getBatchChannelWriteUpdates(idleStages); | ||
await Promise.all([ | ||
deleteStagesWithRetry(idleStageArns), | ||
updateMultipleChannelDynamoItems(batchChannelWriteUpdates) | ||
]); | ||
} | ||
|
||
if (_nextToken) await deleteIdleStages(_nextToken); | ||
}; | ||
|
||
await deleteIdleStages(); | ||
} catch (error) { | ||
console.error(error); | ||
|
||
throw new Error('Failed to remove idle stages due to unexpected error'); | ||
} | ||
}; | ||
|
||
export default handler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters