-
Notifications
You must be signed in to change notification settings - Fork 19
add docker image cleanup #1190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alexcos20
wants to merge
2
commits into
main
Choose a base branch
from
feature/add_docker_image_cleanup
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
add docker image cleanup #1190
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -19,6 +19,8 @@ interface ComputeDatabaseProvider { | |
| fromTimestamp?: string, | ||
| consumerAddrs?: string[] | ||
| ): Promise<DBComputeJob[]> | ||
| updateImage(image: string): Promise<void> | ||
| getOldImages(retentionDays: number): Promise<string[]> | ||
| } | ||
|
|
||
| function getInternalStructure(job: DBComputeJob): any { | ||
|
|
@@ -123,6 +125,66 @@ export class SQLiteCompute implements ComputeDatabaseProvider { | |
| }) | ||
| } | ||
|
|
||
| createImageTable(): Promise<void> { | ||
| const createTableSQL = ` | ||
| CREATE TABLE IF NOT EXISTS docker_images ( | ||
| image TEXT PRIMARY KEY, | ||
| lastUsedTimestamp INTEGER NOT NULL | ||
| ); | ||
| ` | ||
| return new Promise<void>((resolve, reject) => { | ||
| this.db.run(createTableSQL, (err) => { | ||
| if (err) { | ||
| DATABASE_LOGGER.error('Could not create docker_images table: ' + err.message) | ||
| reject(err) | ||
| } else { | ||
| resolve() | ||
| } | ||
| }) | ||
| }) | ||
| } | ||
|
|
||
| updateImage(image: string): Promise<void> { | ||
| const timestamp = Math.floor(Date.now() / 1000) // Unix timestamp in seconds | ||
| const insertSQL = ` | ||
| INSERT OR REPLACE INTO docker_images (image, lastUsedTimestamp) | ||
| VALUES (?, ?); | ||
| ` | ||
| return new Promise<void>((resolve, reject) => { | ||
| this.db.run(insertSQL, [image, timestamp], (err) => { | ||
| if (err) { | ||
| DATABASE_LOGGER.error( | ||
| `Could not update image usage for ${image}: ${err.message}` | ||
| ) | ||
| reject(err) | ||
| } else { | ||
| DATABASE_LOGGER.debug(`Updated image usage timestamp for ${image}`) | ||
| resolve() | ||
| } | ||
| }) | ||
| }) | ||
| } | ||
|
|
||
| getOldImages(retentionDays: number = 7): Promise<string[]> { | ||
| const cutoffTimestamp = Math.floor(Date.now() / 1000) - retentionDays * 24 * 60 * 60 | ||
| const selectSQL = ` | ||
| SELECT image FROM docker_images | ||
| WHERE lastUsedTimestamp < ? | ||
| ORDER BY lastUsedTimestamp ASC; | ||
| ` | ||
| return new Promise<string[]>((resolve, reject) => { | ||
| this.db.all(selectSQL, [cutoffTimestamp], (err, rows: any[] | undefined) => { | ||
| if (err) { | ||
| DATABASE_LOGGER.error(`Could not get old images: ${err.message}`) | ||
| reject(err) | ||
| } else { | ||
| const images = rows ? rows.map((row) => row.image) : [] | ||
| resolve(images) | ||
| } | ||
| }) | ||
| }) | ||
| } | ||
|
|
||
| newJob(job: DBComputeJob): Promise<string> { | ||
| // TO DO C2D | ||
| const insertSQL = ` | ||
|
|
@@ -307,7 +369,7 @@ export class SQLiteCompute implements ComputeDatabaseProvider { | |
| }) | ||
| resolve(filtered) | ||
| } else { | ||
| DATABASE_LOGGER.info('Could not find any running C2D jobs!') | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we still need this log? |
||
| // DATABASE_LOGGER.info('Could not find any running C2D jobs!') | ||
| resolve([]) | ||
| } | ||
| } | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would there be any advantages to do this in parallel with promise.all?