-
-
Notifications
You must be signed in to change notification settings - Fork 42
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
feat(vacuum): add vacuum management for cleaning expired packages #3442
Closed
Closed
Changes from 67 commits
Commits
Show all changes
73 commits
Select commit
Hold shift + click to select a range
bb507ac
chore(lint): refacto setParam to remove complexity
NikitaCOEUR cf7cc90
chore(deps): add go-humanize and bbolt dependencies
NikitaCOEUR c867e8d
feat(vacuum): implement StoreQueue and Controller for vacuum management
NikitaCOEUR 90afe12
test(vacuum): add unit tests for vacuum controller
NikitaCOEUR 491a793
feat(vacuum): define AQUA_VACUUM_DAYS env var
NikitaCOEUR a74ad33
feat(cli): add vacuum command for managing expired packages
NikitaCOEUR 36950ef
feat(installer): add vacuum controller integration
NikitaCOEUR 61308d6
feat(controller): integrate vacuum controller into exec controller
NikitaCOEUR c5858fd
feat(controller): add vacuum command controller initialization
NikitaCOEUR 6a0d661
chore(wire): cmdx wire to regenerate it
NikitaCOEUR cf97223
test(exec): remove unused function
NikitaCOEUR 62066f4
chore(vacuum): make newStoreQueue private function
NikitaCOEUR 046ab6e
chore(install): defer close vacuum to ensure async finalized
NikitaCOEUR 0162444
chore(vacuum): use int instead of pointer
NikitaCOEUR 77bcc0e
chore(vacuum): refactor CLI commands for vacuum operations
NikitaCOEUR f09bf45
chore(vacuum): use public functions instead of mode
NikitaCOEUR 7290f55
chore(vacuum): refactor vacuum closing logic and update controller in…
NikitaCOEUR b5a7651
chore(controller): update wire_gen.go via cmdx wire
NikitaCOEUR 2cb4eb0
chore(mod): update go.mod with go mod tidy
NikitaCOEUR 84636e4
tests(vacuum): fix lint tests
NikitaCOEUR 24c573f
tests(vacuum): remove unused param
NikitaCOEUR a8b1d21
tests(vacuum): remove unused const
NikitaCOEUR 11ff335
chore(cli): remove default vacuum days setting
NikitaCOEUR 470a28e
docs(vacuum): update command descriptions for clarity
NikitaCOEUR 6a18879
fix(controller): use filepath.Join for constructing database file path
NikitaCOEUR f394fe9
fix(controller): improve error logging during database operation retries
NikitaCOEUR d9e093e
fix(controller): simplify error handling in database update and view …
NikitaCOEUR db19074
fix(controller): use filepath.Join for database file path constructio…
NikitaCOEUR 4325fbd
fix(controller): enhance error handling in TestKeepDBOpen and update …
NikitaCOEUR a67cb3a
fix(controller): improve error logging in package decoding and simpli…
NikitaCOEUR 8b0b7cd
fix(controller): enhance error logging for package removal and improv…
NikitaCOEUR 2001127
fix(controller): update logging fields for package storage to improve…
NikitaCOEUR 81df2bd
fix(controller): simplify error messages in package display and encod…
NikitaCOEUR d8ae573
fix(controller): remove parent directory cleanup to keep aqua simple
NikitaCOEUR 1b71a57
chore(lint): fix lint error
NikitaCOEUR d2000a8
test(controller): add unit tests for package entry encoding and decoding
NikitaCOEUR e1d47fb
test(workflow): add integration test for vacuum run command
NikitaCOEUR fc4ead0
chore(vacuum): fix lint tests
NikitaCOEUR abd0bf4
ci(vacuum): run vacuum command before update aqua
NikitaCOEUR 07fcc26
fix: replace time.Sleep with timer.Wait to support cancel
suzuki-shunsuke 94e7725
ci(workflow): add test aqua command with vacuum enabled
NikitaCOEUR fa79338
fix: replace time.Sleep with timer.Wait for cancel
suzuki-shunsuke a66f099
fix: handle an error of timer.Wait
suzuki-shunsuke fdd9ff0
tests(vacuum): set specific logger for each test
NikitaCOEUR 99f6456
tests(vacuum): replace assert and require with testing and go-cmp
NikitaCOEUR 457e699
tests(vacuum): fix lints
NikitaCOEUR 1b55c9d
tests(vacuum): add sleep to ensure logs catched before end of test
NikitaCOEUR 087e6f2
chore(mod): execute go mod tidy
NikitaCOEUR ee5e23c
test(vacuum): add packages to let all async log on fail appears
NikitaCOEUR eb86893
test(vacuum): replace afero.TempDir with t.TempDir
NikitaCOEUR 7721951
refactor: minimize the scope of err variables
suzuki-shunsuke 4fa6410
refactor: replace contains with strings.HasPrefix
suzuki-shunsuke ec0a987
refactor: remove generatePackageKey
suzuki-shunsuke eda0509
fix: fix pkgPath
suzuki-shunsuke 24e1d7e
refactor: refactor
suzuki-shunsuke a6353c1
fix: skip updating DB when a package install is skipped
suzuki-shunsuke 1a3f886
refactor: separate code about DB
suzuki-shunsuke ffbd7e0
refactor: rename a method
suzuki-shunsuke 6e65072
refactor: separate code about DB
suzuki-shunsuke 596a6a4
fix: fix lint errors
suzuki-shunsuke 3070a5d
fix: fix compile errors
suzuki-shunsuke 2fb9ef4
refactor: refactor
suzuki-shunsuke 3c24a2a
refactor: refactor
suzuki-shunsuke c48052c
refactor: close database in cli packages
suzuki-shunsuke 0f035e1
fix: stop updating timestamp twice
suzuki-shunsuke b875c9c
fix: suppress a lint error
suzuki-shunsuke 45981e4
refactor: separate code
suzuki-shunsuke 4771a90
fix(exec): fix a bug that DB isn't closed
suzuki-shunsuke f815a6a
style: sort methods
suzuki-shunsuke 8eb89a0
fix: remove package type from db
suzuki-shunsuke feb29c2
refactor: rename a field
suzuki-shunsuke 0dadc30
refactor: remove an unused field
suzuki-shunsuke 337188f
refactor: refactor
suzuki-shunsuke 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 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
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,111 @@ | ||
package vacuum | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/aquaproj/aqua/v2/pkg/cli/profile" | ||
"github.com/aquaproj/aqua/v2/pkg/cli/util" | ||
"github.com/aquaproj/aqua/v2/pkg/config" | ||
"github.com/aquaproj/aqua/v2/pkg/controller" | ||
"github.com/suzuki-shunsuke/logrus-error/logerr" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
const description = `Perform vacuuming tasks. | ||
|
||
Enable vacuuming by setting the AQUA_VACUUM_DAYS environment variable to a value greater than 0. | ||
This command removes versions of packages that have not been used for the specified number of days. | ||
|
||
You can list all packages managed by the vacuum system or only expired packages. | ||
|
||
# Show all packages managed by the vacuum system | ||
$ aqua vacuum show | ||
|
||
# Show only expired packages | ||
$ aqua vacuum show --expired | ||
$ aqua vacuum show -e | ||
|
||
# Run vacuum cleaning | ||
$ aqua vacuum run | ||
` | ||
|
||
type command struct { | ||
r *util.Param | ||
} | ||
|
||
func New(r *util.Param) *cli.Command { | ||
i := &command{ | ||
r: r, | ||
} | ||
return &cli.Command{ | ||
Name: "vacuum", | ||
Usage: "Operate vacuuming tasks (If AQUA_VACUUM_DAYS is set)", | ||
Aliases: []string{"v"}, | ||
Description: description, | ||
Subcommands: []*cli.Command{ | ||
{ | ||
Name: "show", | ||
Aliases: []string{"s"}, | ||
Usage: "Show packages managed by vacuum system", | ||
Action: i.action, | ||
Flags: []cli.Flag{ | ||
&cli.BoolFlag{ | ||
Name: "expired", | ||
Usage: "Show only expired packages", | ||
Aliases: []string{"e"}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Name: "run", | ||
Aliases: []string{"r"}, | ||
Usage: "Run vacuum cleaning", | ||
Action: i.action, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (i *command) action(c *cli.Context) error { | ||
profiler, err := profile.Start(c) | ||
if err != nil { | ||
return fmt.Errorf("start CPU Profile or tracing: %w", err) | ||
} | ||
defer profiler.Stop() | ||
|
||
logE := i.r.LogE | ||
|
||
param := &config.Param{} | ||
if err := util.SetParam(c, logE, "vacuum", param, i.r.LDFlags); err != nil { | ||
return fmt.Errorf("parse the command line arguments: %w", err) | ||
} | ||
|
||
if param.VacuumDays == 0 { | ||
return errors.New("vacuum is not enabled, please set the AQUA_VACUUM_DAYS environment variable") | ||
} | ||
suzuki-shunsuke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
ctrl := controller.InitializeVacuumCommandController(c.Context, param, http.DefaultClient, i.r.Runtime) | ||
|
||
defer func() { | ||
if err := ctrl.Close(logE); err != nil { | ||
logerr.WithError(logE, err).Error("close vacuum controller") | ||
} | ||
}() | ||
|
||
if c.Command.Name == "show" { | ||
if err := ctrl.ListPackages(c.Context, logE, c.Bool("expired")); err != nil { | ||
return fmt.Errorf("show packages: %w", err) | ||
} | ||
return nil | ||
} | ||
|
||
if c.Command.Name == "run" { | ||
if err := ctrl.Vacuum(c.Context, logE); err != nil { | ||
return fmt.Errorf("run: %w", err) | ||
} | ||
} | ||
|
||
return nil | ||
} |
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
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.
Note that I don't think this works here, because aqua exec can use: https://github.com/aquaproj/aqua/blob/main/pkg/controller/exec/exec.go#L126.
And this (on UNIX) uses the "Exec" function of syscall_unix, which, when executed, replaces the calling process with the called process.
This cuts short the rest of the code, and the functions called in defer are not played. Finally, asynchronous processes are not necessarily terminated either...
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.
Oh, I see. Thank you.
I've confirmed defer function isn't executed.
https://pkg.go.dev/golang.org/x/sys/unix#Exec
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.
4771a90